Drafts of Leetcode July 2022
2022年7月力扣.
❗ 💛 241. 为运算表达式设计优先级
想法1: eval()
可以直接计算带括号的表达式, 想办法加括号;
想法2: DP, 每次判断一个运算符, 但要储存一个运算了的子字符串集合,
否则可能会算重. (对于输入expression = "2*3-4*5"
,
((2*3)-(4*5)) = -14
这一结果代表了两种运算顺序),
这里我每一次找的运算符是最先运算的, 从题解来看,
应该要找最后运算的运算符
Python/Golang 分治算法 - 江不知
1 | class Solution: # DC三步走, 解法非常优雅 |
写两个例子例子: expression = "2-1-1"
,
expression = "2*3-4*5"
, 便于理解.
1 | input: expression = "2-1-1" |
1 | input: expression = "2*3-4*5" |
🛠 str.isdigit
()
Return True if all characters in the string are digits and there is at least one character, False otherwise. Digits include decimal characters and digits that need special handling, such as the compatibility superscript digits. This covers digits which cannot be used to form numbers in base 10, like the Kharosthi numbers. Formally, a digit is a character that has the property value Numeric_Type=Digit or Numeric_Type=Decimal. 如果字符串中的所有字符都是数字且至少有一个字符,则返回True,否则返回False。数字包括十进制字符和需要特殊处理的数字,如兼容上标数字。这包括那些不能用来组成以10为基数的数字的数字,如Kharosthi数字。从形式上看,数字是一个具有Numeric_Type=Digit或Numeric_Type=Decimal属性值的字符。
Python String isdigit() Method: 三种类型的示例
[Python/Java/TypeScript/Go] 区间DP - Benhao
❤ ==871. 最低加油次数==
在学PPO, 摸了.
🎯 第 300 场周赛 - NIO 蔚来
12 / 18, 1731 / 6792.
💛 556. 下一个更大元素 III
数学 - Carlos
1 | class Solution: # 从后到前遍历下标-i, 再遍历-i后的所有下标-j, 一旦发现-i对应的元素小, 就可以换, 之后把后面的元素倒序排列即可 |
💚 1200. 最小绝对差
排序后np.diff
- Carlos
1 | class Solution: # 暴力组合TLE |
1 | import numpy as np |
[Python/Java/TypeScript/Go] 排序模拟 - Benhao
1 | class Solution: |