当前位置:网站首页>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;
}
}
边栏推荐
- 51 single chip microcomputer timer 2 is used as serial port
- Notice on Soliciting Opinions on the draft of information security technology mobile Internet application (APP) life cycle security management guide
- C import Xls data method summary II (save the uploaded file to the DataTable instance object)
- 2022 R2 mobile pressure vessel filling certificate examination and R2 mobile pressure vessel filling simulation examination questions
- MySQL advanced (Advanced) SQL statement (I)
- Chapter 3.4: starrocks data import - Flink connector and CDC second level data synchronization
- Small program graduation project based on wechat reservation small program graduation project opening report reference
- Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
- In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
- How can enterprises optimize the best cost of cloud computing?
猜你喜欢
Life cycle of instance variables, static variables and local variables
On Valentine's day, I code a programmer's exclusive Bing Dwen Dwen (including the source code for free)
Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page
Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files
Write the first CUDA program
Introduction to superresolution
How can enterprises optimize the best cost of cloud computing?
Use classname to modify style properties
MySQL advanced SQL statement (1)
How programmers find girlfriends through blind dates
随机推荐
求esp32C3板子連接mssql方法
Human resource management online assignment
What is the intelligent monitoring system of sewage lifting pump station and does it play a big role
LeetCode 168. Detailed explanation of Excel list name
C import Xls data method summary I (upload files and create Workbooks)
MySQL introduction - functions (various function statistics, exercises, details, tables)
Ka! Why does the seat belt suddenly fail to pull? After reading these pictures, I can't stop wearing them
MPLS③
Feign implements dynamic URL
Neo4j learning notes
MySQL advanced (Advanced) SQL statement (I)
Create template profile
A. ABC
Pyrethroid pesticide intermediates - market status and future development trend
When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
Solution to the problem that jsp language cannot be recognized in idea
Jerry's synchronous weather information to equipment [chapter]
Life cycle of instance variables, static variables and local variables
Sequence sorting of basic exercises of test questions
Prose article appreciation - the rain in the warm country has never changed into cold, hard and brilliant flowers. Knowledgeable people think he is monotonous, and he thinks he is unlucky, doesn't he?