classSolution { public: intevalRPN(vector<string>& tokens){ vector<int> nums; for(int i = 0; i < tokens.size(); i++){ string s = tokens[i]; if(s.size() == 1 && (s == "+" || s == "-" || s == "*" || s == "/")){ int a = nums.back(); nums.pop_back(); int b = nums.back(); nums.pop_back(); int re; switch(s[0]){ case'+': re = a + b; break; case'-': re = b - a; break; case'*': re = b * a; break; case'/': re = b / a; break; } nums.push_back(re); } else{ nums.push_back(stoi(s)); } } return nums[0]; } };
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.
get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
set(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m subarrays.
Note:
Given m satisfies the following constraint: 1 ≤ m ≤ length(nums) ≤ 14,000.
Examples:
1 2 3 4 5 6 7 8 9 10 11
Input: nums = [7,2,5,10,8] m = 2
Output: 18
Explanation: There are four ways to split nums into two subarrays. The best way is to split it into [7,2,5] and [10,8], where the largest sum among the two subarrays is only 18.