当前位置:网站首页>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;
}
边栏推荐
- SQL injection base
- Dump文件生成,内容,以及分析
- Pagoda Test-Building PHP Online Mock Exam System
- SAS data processing technology (1)
- [数据可视化] 图表设计原则
- NOR FLASH闪存芯片ID应用之软件保护场景
- 16. File upload
- 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?
- What is the ASIO4ALL
- Part of the reserve bank is out of date
猜你喜欢
Jvm.分析工具(jconsole,jvisualvm,arthas,jprofiler,mat)
[Excel知识技能] 将数值格式数字转换为文本格式
学习Apache ShardingSphere解析器源码(一)
Special class and type conversion
Design and Realization of Employment Management System in Colleges and Universities
【.NET Core】使用 NPOI 读写Excel 文件
有哪些可以投稿软件工程/系统软件/程序设计语言类外文期刊、会议?
【redis】发布和订阅消息
9. Rest 风格请求处理
YOLOv5的Tricks | 【Trick12】YOLOv5使用的数据增强方法汇总
随机推荐
14. Thymeleaf
好用的翻译插件-一键自动翻译插件软件
百战RHCE(第四十八战:运维工程师必会技-Ansible学习3-构建Ansible清单)
[Data Visualization] Chart Design Principles
electron -autoUpdater 更新
“蔚来杯“2022牛客暑期多校训练营3 DF题解
iNFTnews | Web3时代,用户将拥有数据自主权
How to recover deleted files from the recycle bin, two methods of recovering files from the recycle bin
Where can I download IEEE papers?
[C language] binary search (half search)
编程语言为什么有变量类型这个概念?
Go项目配置管理神器之viper使用详解
LENS CRA和SENSOR CRA匹配问题解析
YOLOv5的Tricks | 【Trick12】YOLOv5使用的数据增强方法汇总
7. yaml
学习Apache ShardingSphere解析器源码(一)
ROS Experimental Notes - Install QPEP and Intel-MKL
【经典排序】快速排序
iNFTnews | In the Web3 era, users will have data autonomy
10. Notes on receiving parameters