当前位置:网站首页>Sword finger offer 20 String representing numeric value
Sword finger offer 20 String representing numeric value
2022-07-04 01:59:00 【South wind knows easy***】
. Can't appear before . perhaps e;
e You have to appear before ,e Then there must be an integer
± Appear in the 0 Location or e/E The first position behind is legal
class Solution {
public boolean isNumber(String s) {
if(s == null || s.length() == 0){
return false;
}
// Mark whether the corresponding situation is encountered
boolean numSeen = false;
boolean dotSeen = false;
boolean eSeen = false;
char[] str = s.trim().toCharArray();
for(int i = 0;i < str.length; i++){
if(str[i] >= '0' && str[i] <= '9'){
numSeen = true;
}else if(str[i] == '.'){
//. Can't appear before . perhaps e
if(dotSeen || eSeen){
return false;
}
dotSeen = true;
}else if(str[i] == 'e' || str[i] == 'E'){
//e Can't appear before e, Number of required occurrences
if(eSeen || !numSeen){
return false;
}
eSeen = true;
numSeen = false;// Reset numSeen, exclude 123e perhaps 123e+ The situation of , Make sure e Then there are several
}else if(str[i] == '-' || str[i] == '+'){
//+- Appear in the 0 Location or e/E The first position behind is legal
if(i != 0 && str[i-1] != 'e' && str[i-1] != 'E'){
return false;
}
}else{
// Other illegal characters
return false;
}
}
return numSeen;
}
}
边栏推荐
- Openbionics robot project introduction | bciduino community finishing
- Summarize the past to motivate yourself to move on
- In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
- Do you know the eight signs of a team becoming agile?
- Applet graduation project based on wechat selection voting applet graduation project opening report function reference
- Setting function of Jerry's watch management device [chapter]
- Containerization technology stack
- Feign implements dynamic URL
- Conditional test, if, case conditional test statements of shell script
- Trading software programming
猜你喜欢
SRCNN:Learning a Deep Convolutional Network for Image Super-Resolution
Example 073 square sum value judgment programming requires the input of a and B, if a ²+ b ² If the result of is greater than 100, a is output ²+ b ² Value, otherwise output the result of a + B.
TP5 automatic registration hook mechanism hook extension, with a complete case
MySQL advanced SQL statement (1)
Small program graduation project based on wechat examination small program graduation project opening report function reference
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
LeetCode 168. Detailed explanation of Excel list name
Mysql-15 aggregate function
Install the pit that the electron has stepped on
Introduction to superresolution
随机推荐
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
What are the main investment products of bond funds and what are they
Neo4j learning notes
I don't know why it can't run in the project and how to change it
Jerry's modification setting status [chapter]
Lightweight Pyramid Networks for Image Deraining
1189. Maximum number of "balloons"
[typora installation package] old typera installation package, free version
A. Div. 7
LV1 previous life archives
JVM performance tuning and practical basic theory - medium
Feign implements dynamic URL
ThinkPHP uses redis to update database tables
Small program graduation project based on wechat examination small program graduation project opening report function reference
Do you know the eight signs of a team becoming agile?
Ceramic metal crowns - current market situation and future development trend
Hamburg University of Technology (tuhh) | intelligent problem solving as integrated hierarchical reinforcement learning
JVM performance tuning and practical basic theory - medium
Solution to the problem that jsp language cannot be recognized in idea
Mysql-15 aggregate function