当前位置:网站首页>leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
2022-07-07 15:35:00 【InfoQ】
One 、 The main idea of the topic
- 1 <= expression.length <= 20
- expression By numbers and operators '+'、'-' and '*' form .
- All integer values in the input expression are in the range [0, 99]
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
public class Solution {
public List<Integer> diffWaysToCompute(String expression) {
List<Integer> ans = new ArrayList<>();
for (int i = 0; i < expression.length(); i++) {
char ope = expression.charAt(i);
if (ope == '+' || ope == '-' || ope == '*') {
List<Integer> left = diffWaysToCompute(expression.substring(0, i));
List<Integer> right = diffWaysToCompute(expression.substring(i + 1));
for (int l : left) {
for (int r : right) {
switch (ope) {
case '+':
ans.add(l + r);
break;
case '-':
ans.add(l - r);
break;
case '*':
ans.add(l * r);
break;
}
}
}
}
}
if (ans.isEmpty()) {
ans.add(Integer.valueOf(expression));
}
return ans;
}
}
Four 、 Summary notes
- 2022/7/7 ' , Another week's delay
边栏推荐
- Comparable and comparator of sorting
- 【原创】一切不谈考核的管理都是扯淡!
- 【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例
- Concurrency Control & NoSQL and new database
- There is a cow, which gives birth to a heifer at the beginning of each year. Each heifer has a heifer at the beginning of each year since the fourth year. Please program how many cows are there in the
- Novel Slot Detection: A Benchmark for Discovering Unknown Slot Types in the Dialogue System
- @ComponentScan
- Connecting FTP server tutorial
- Ctfshow, information collection: web14
- [deep learning] semantic segmentation experiment: UNET network /msrc2 dataset
猜你喜欢

CTFshow,信息搜集:web10

Unity之ASE实现全屏风沙效果

CTFshow,信息搜集:web12
![[understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper](/img/38/cc5bb5eaa3dcee5ae2d51a904cf26a.png)
[understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper
![[quickstart to Digital IC Validation] 20. Basic syntax for system verilog Learning 7 (Coverage Driven... Including practical exercises)](/img/d3/cab8a1cba3c8d8107ce4a95f328d36.png)
[quickstart to Digital IC Validation] 20. Basic syntax for system verilog Learning 7 (Coverage Driven... Including practical exercises)

“百度杯”CTF比赛 2017 二月场,Web:include
![[quick start of Digital IC Verification] 20. Basic grammar of SystemVerilog learning 7 (coverage driven... Including practical exercises)](/img/d3/cab8a1cba3c8d8107ce4a95f328d36.png)
[quick start of Digital IC Verification] 20. Basic grammar of SystemVerilog learning 7 (coverage driven... Including practical exercises)

Unity's ASE realizes cartoon flame

【数字IC验证快速入门】25、SystemVerilog项目实践之AHB-SRAMC(5)(AHB 重点回顾,要点提炼)

2022全开源企业发卡网修复短网址等BUG_2022企业级多商户发卡平台源码
随机推荐
2. Heap sort "hard to understand sort"
HW初级流量监控,到底该怎么做
Ctfshow, information collection: web4
Ctfshow, information collection: web1
The bank needs to build the middle office capability of the intelligent customer service module to drive the upgrade of the whole scene intelligent customer service
广州开发区让地理标志产品助力乡村振兴
Niuke real problem programming - day14
写一篇万字长文《CAS自旋锁》送杰伦的新专辑登顶热榜
"Baidu Cup" CTF competition 2017 February, web:include
Unity之ASE实现卡通火焰
Novel Slot Detection: A Benchmark for Discovering Unknown Slot Types in the Dialogue System
[机缘参悟-40]:方向、规则、选择、努力、公平、认知、能力、行动,读3GPP 6G白皮书的五层感悟
Niuke real problem programming - Day9
CTFshow,信息搜集:web5
Summer safety is very important! Emergency safety education enters kindergarten
一个需求温习到的所有知识,h5的表单被键盘遮挡,事件代理,事件委托
Configure mongodb database in window environment
Starting from 1.5, build a microservice framework link tracking traceid
Ctfshow, information collection: web13
Ctfshow, information collection: web10