{"id":22513867,"url":"https://github.com/emahtab/evaluate-reverse-polish-notation","last_synced_at":"2026-01-30T08:51:10.458Z","repository":{"id":79525478,"uuid":"233863914","full_name":"eMahtab/evaluate-reverse-polish-notation","owner":"eMahtab","description":"Evaluate Reverse Polish Expression","archived":false,"fork":false,"pushed_at":"2020-01-14T14:53:55.000Z","size":3,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T03:25:47.378Z","etag":null,"topics":["leetcode","problem-solving","reverse-polish-notation","stack"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-14T14:48:13.000Z","updated_at":"2020-01-14T14:55:25.000Z","dependencies_parsed_at":"2023-05-10T17:15:48.020Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/evaluate-reverse-polish-notation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fevaluate-reverse-polish-notation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fevaluate-reverse-polish-notation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fevaluate-reverse-polish-notation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fevaluate-reverse-polish-notation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/evaluate-reverse-polish-notation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245952138,"owners_count":20699433,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["leetcode","problem-solving","reverse-polish-notation","stack"],"created_at":"2024-12-07T03:14:45.028Z","updated_at":"2026-01-30T08:51:10.429Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Evaluate Reverse Polish Notation \n## https://leetcode.com/problems/evaluate-reverse-polish-notation\n\nEvaluate the value of an arithmetic expression in Reverse Polish Notation.\n\nValid operators are +, -, *, /. Each operand may be an integer or another expression.\n\nNote:\n1. Division between two integers should truncate toward zero.\n2. The given RPN expression is always valid. That means the expression would always evaluate to a result and there won't be any divide by zero operation.\n\n```\nExample 1:\n\nInput: [\"2\", \"1\", \"+\", \"3\", \"*\"]\nOutput: 9\nExplanation: ((2 + 1) * 3) = 9\n\nExample 2:\n\nInput: [\"4\", \"13\", \"5\", \"/\", \"+\"]\nOutput: 6\nExplanation: (4 + (13 / 5)) = 6\n\nExample 3:\n\nInput: [\"10\", \"6\", \"9\", \"3\", \"+\", \"-11\", \"*\", \"/\", \"*\", \"17\", \"+\", \"5\", \"+\"]\nOutput: 22\nExplanation: \n  ((10 * (6 / ((9 + 3) * -11))) + 17) + 5\n= ((10 * (6 / (12 * -11))) + 17) + 5\n= ((10 * (6 / -132)) + 17) + 5\n= ((10 * 0) + 17) + 5\n= (0 + 17) + 5\n= 17 + 5\n= 22\n```\n## Implementation :\n\n```java\n  public static int evalRPN(String[] tokens) {\n      Stack\u003cInteger\u003e st = new  Stack\u003c\u003e();\n      for(String s : tokens){\n        if(isOperator(s)){\n         int rightOperand = st.pop();\n         int leftOperand = st.pop();\n         st.push(evaluate(leftOperand, rightOperand, s));\n        } else{\n          st.push(Integer.parseInt(s));\n        }\n      }\n      return st.pop();\n  }\n\n  private static boolean isOperator(String token) {\n    if (token.equals(\"+\") || token.equals(\"-\") || token.equals(\"*\") \n        || token.equals(\"/\")) {\n      return true;\n    }\n    return false;\n  }\n\n  private static int evaluate(int left, int right , String operator){\n    int result = 0;\n    switch(operator){\n        case \"+\" : result = left + right; break;\n        case \"-\" : result = left - right; break;\n        case \"*\" : result = left * right; break;\n        case \"/\" : result = left / right; break;\n    }\n    return result;\n  }\n```\nAbove implementation have runtime complexity of O(n) and space complexity of O(n), where n is the number of elements in the input `tokens` array.\n```\nRuntime Complexity = O(n)\nSpace Complexity   = O(n)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fevaluate-reverse-polish-notation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fevaluate-reverse-polish-notation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fevaluate-reverse-polish-notation/lists"}