当前位置:网站首页>2022.8.10-----leetcode.640
2022.8.10-----leetcode.640
2022-08-10 23:57:00 【路Lu727】
public String solveEquation(String equation) {
int c=0;//常数
int co=0;//系数
String[] ss=equation.split("=");//分成左右式子
for(int i=0,j=1;i<ss[0].length();){
while(j<ss[0].length()){
if(ss[0].charAt(j)=='+'||ss[0].charAt(j)=='-')
break;
j++;
}
if(ss[0].charAt(j-1)=='x'){
String num=ss[0].substring(i,j-1);
//+-1单独判断
if(num.equals("")||num.equals("+"))
co+=1;
else if(num.equals("-"))
co-=1;
else co+=Integer.parseInt(num);
}else{
c-=Integer.parseInt(ss[0].substring(i,j));
}
i=j++;
}
for(int i=0,j=1;i<ss[1].length();){
while(j<ss[1].length()){
if(ss[1].charAt(j)=='+'||ss[1].charAt(j)=='-')
break;
j++;
}
if(ss[1].charAt(j-1)=='x'){
String num=ss[1].substring(i,j-1);
if(num.equals("")||num.equals("+"))
co-=1;
else if(num.equals("-"))
co+=1;
else co-=Integer.parseInt(num);
}else{
c+=Integer.parseInt(ss[1].substring(i,j));
}
i=j++;
}
if(co==0) {
if(c==0)
return "Infinite solutions";
else return "No solution";
}else return "x="+c/co;
}
边栏推荐
- Which foreign language journals and conferences can be submitted for software engineering/system software/programming language?
- PMP每日一练 | 考试不迷路-8.10(包含敏捷+多选)
- Easy-to-use translation plug-in - one-click automatic translation plug-in software
- 【js】获取当前时间的前后n天或前后n个月(时分秒年月日都可)
- 15. 拦截器-HandlerInterceptor
- Pagoda Test-Building PHP Online Mock Exam System
- Analysis of LENS CRA and SENSOR CRA Matching Problems
- 11. 自定义转换器
- [Excel知识技能] 将文本型数字转换为数值格式
- [Data Visualization] Chart Design Principles
猜你喜欢
14. Thymeleaf
给肯德基打工的调料商,年赚两亿
回收站的文件删了怎么恢复,回收站文件恢复的两种方法
There is no recycle bin for deleted files on the computer desktop, what should I do if the deleted files on the desktop cannot be found in the recycle bin?
深度学习 Transformer架构解析
web 性能提升(将持续更新……)
Server Tips
5. Lombok
李彦宏拆墙交朋友,大厂“塑料友情”能否帮百度啃下硬骨头?
nodejs项目连接mysql数据库
随机推荐
[Data Visualization] Chart Design Principles
Web-based meal ordering system in epidemic quarantine area
[Excel knowledge and skills] Convert "false" date to "true" date format
SAS data processing technology (1)
13. Content Negotiation
Analysis of LENS CRA and SENSOR CRA Matching Problems
编程语言为什么有变量类型这个概念?
9. Rest style request processing
Multilingual Translation - Multilingual Translation Software Free
12. Handling JSON
Promise in detail
【.NET Core】使用 NPOI 读写Excel 文件
李彦宏拆墙交朋友,大厂“塑料友情”能否帮百度啃下硬骨头?
Is there a way out in the testing industry if it is purely business testing?
Timers, synchronous and asynchronous APIs, file system modules, file streams
7. yaml
[C] the C language program design, dynamic address book (order)
leetcode 前K个高频单词
分布式.性能优化
[C language] Detailed explanation of data storage