当前位置:网站首页>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;
}边栏推荐
猜你喜欢

【爬虫】scrapy创建运行爬虫、解析页面(嵌套url)、自定义中间件(设置UserAgent和代理IP)、自定义管道(保存到mysql)
![[C language articles] Expression evaluation (implicit type conversion, arithmetic conversion)](/img/ae/74dc5fc676e74ab03607565ca7539e.png)
[C language articles] Expression evaluation (implicit type conversion, arithmetic conversion)

Deep Learning Transformer Architecture Analysis
![[Data Visualization] Chart Design Principles](/img/f3/691dd58d1e334f9f62efa23e27ec76.png)
[Data Visualization] Chart Design Principles

2. 依赖管理和自动配置
![[Excel knowledge and skills] Convert](/img/96/ece9c3885fd4abe4bf4d211813b9c4.png)
[Excel knowledge and skills] Convert "false" date to "true" date format

SQL注入基础

Starting a new journey - Mr. Maple Leaf's first blog

"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 3 DF Problem Solving

有哪些可以投稿软件工程/系统软件/程序设计语言类外文期刊、会议?
随机推荐
好用的翻译插件-一键自动翻译插件软件
13. 内容协商
Three-column layout implementation
Summary of Confused Knowledge Points for "High Items" in the Soft Examination in the Second Half of 2022 (2)
报错:Client does not support authentication protocol requested by server; consider upgrading MySQL cli
图片懒加载(纯手写)
李彦宏拆墙交朋友,大厂“塑料友情”能否帮百度啃下硬骨头?
Web-based meal ordering system in epidemic quarantine area
Design and implementation of flower online sales management system
Why do programming languages have the concept of variable types?
14. Thymeleaf
"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 4 ADHK Problem Solving
虚拟电厂可视化大屏,深挖痛点精准减碳
力扣每日一题-第52天-387. 字符串中的第一个唯一字符
英文文献阅读时,如何做笔记?
深度学习 Transformer架构解析
工程师如何对待开源
10. Notes on receiving parameters
2022下半年软考「高项」易混淆知识点汇总(2)
Where can I download IEEE papers?