当前位置:网站首页>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;
}
}
边栏推荐
- [leetcode daily question] a single element in an ordered array
- Jerry's update contact [article]
- Luogu p1309 Swiss wheel
- Special copy UML notes
- Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
- Create template profile
- Trading software programming
- Cancer biopsy instruments and kits - market status and future development trends
- Why is the operation unsuccessful (unresolved) uncaught syntaxerror: invalid or unexpected token (resolved)
- Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]
猜你喜欢

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.

When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview

Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference

Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?

Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends

2020-12-02 SSM advanced integration Shang Silicon Valley

Feign implements dynamic URL

ES6 deletes an attribute in all array objects through map, deconstruction and extension operators

Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page

Mysql-15 aggregate function
随机推荐
How programmers find girlfriends through blind dates
Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends
Yyds dry goods inventory override and virtual of classes in C
The difference between lambda expressions and anonymous inner classes
Difference between value and placeholder
Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
Meta metauniverse female safety problems occur frequently. How to solve the related problems in the metauniverse?
Question C: Huffman tree
Feign implements dynamic URL
求esp32C3板子連接mssql方法
LV1 previous life archives
Day05 branch and loop (II)
Chapter 3.4: starrocks data import - Flink connector and CDC second level data synchronization
IPv6 experiment
MySQL statement learning record
Writeup (real questions and analysis of ciscn over the years) of the preliminary competition of national college students' information security competition
When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
MySQL advanced (Advanced) SQL statement (I)
Skku| autonomous handover decision of UAV Based on deep reinforcement learning
[typora installation package] old typera installation package, free version