【leetcode】Basic Calculator III】的更多相关文章

题目如下: Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces . The expression string contains only no…
Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces . The expression string contains only non-nega…
这道题就可以结合Basic Calculator中的两种做法了,分别是括号运算和四则运算的,则使用stack作为保持的结果,而使用递归来处理括号内的值的. class Solution { public: int calculate(string s) { ,res=,n=s.size(); stack<int> st; char op='+'; ;i<n;i++){ char c=s[i]; '){ num=num*+c-'; }else if(c=='('){ ; for(;i<…
这道题是LeetCode里的第991道题. 题目描述: 在显示着数字的坏计算器上,我们可以执行以下两种操作: 双倍(Double):将显示屏上的数字乘 2: 递减(Decrement):将显示屏上的数字减 1 . 最初,计算器显示数字 X. 返回显示数字 Y 所需的最小操作数. 示例 1: 输入:X = 2, Y = 3 输出:2 解释:先进行双倍运算,然后再进行递减运算 {2 -> 4 -> 3}. 示例 2: 输入:X = 5, Y = 8 输出:2 解释:先递减,再双倍 {5 ->…
1. Description The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized tha…
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Ensure that numbers within the set are sorted in ascending order. Example 1…
[3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring (2019年1月22日,复习) [6]ZigZag Conversion (2019年1月22日,复习) [8]String to Integer (atoi) (2019年1月22日,复习) [10]Regular Expression Matching (2019年1月22日,复习) [12]In…
[20]Valid Parentheses (2018年11月28日,复习, ko) 给了一个字符串判断是不是合法的括号配对. 题解:直接stack class Solution { public: bool isValid(string s) { set<char> st{'(', '[', '{'}; map<char, char> mp{{'(', ')'}, {'{', '}'}, {'[', ']'}}; stack<char> stk; for (auto…
[2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/9797184.html [7]Reverse Integer (2018年12月23日, review) 给了一个32位的整数,返回它的reverse后的整数.如果reverse后的数超过了整数的范围,就返回 0. Example 1: Input: 123 Output: 321 Example 2:…
[1]Two Sum (2018年11月9日,k-sum专题,算法群衍生题) 给了一个数组 nums, 和一个 target 数字,要求返回一个下标的 pair, 使得这两个元素相加等于 target . 题解:我这次最大范围的优化代码, hash-table + one pass,时间复杂度 O(N),空间复杂度 O(N).重点在于动态找,一边生成hash-table的同时去找答案,不是先生成hash-table再开始找答案. //这种类似 hash 的能用 unordered_map 就不要…