当前位置:网站首页>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;
}
}
边栏推荐
- Pesticide synergist - current market situation and future development trend
- The difference between lambda expressions and anonymous inner classes
- Feign implements dynamic URL
- Write the first CUDA program
- ThinkPHP uses redis to update database tables
- PMP daily three questions (February 14, 2022)
- The reasons why QT fails to connect to the database and common solutions
- Yyds dry goods inventory hand-in-hand teach you the development of Tiktok series video batch Downloader
- MySQL advanced SQL statement (1)
- Create template profile
猜你喜欢

Conditional statements of shell programming

What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended

Three layer switching ②

High level application of SQL statements in MySQL database (I)

Push technology practice | master these two tuning skills to speed up tidb performance a thousand times!

Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files

A fan summed up so many interview questions for you. There is always one you need!

Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
![After listening to the system clear message notification, Jerry informed the device side to delete the message [article]](/img/0c/52816b75eb702c7c63966578ab4969.jpg)
After listening to the system clear message notification, Jerry informed the device side to delete the message [article]

Save Private Ryan - map building + voltage dp+deque+ shortest circuit
随机推荐
LeetCode 168. Detailed explanation of Excel list name
MySQL statement learning record
JVM performance tuning and practical basic theory - medium
Containerization technology stack
Lightweight Pyramid Networks for Image Deraining
MySQL introduction - functions (various function statistics, exercises, details, tables)
What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
PMP daily three questions (February 14, 2022)
Development of user-defined navigation bar in uniapp
Remember another interview trip to Ali, which ends on three sides
Applet graduation project based on wechat selection voting applet graduation project opening report function reference
Sequence sorting of basic exercises of test questions
High level application of SQL statements in MySQL database (I)
Use classname to modify style properties
2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
ThinkPHP uses redis to update database tables
Small program graduation project based on wechat examination small program graduation project opening report function reference
C import Xls data method summary I (upload files and create Workbooks)
Make drop-down menu
All ceramic crowns - current market situation and future development trend