leetcode valid number
细节很多,不是很容易做对
class Solution {
public:bool isNumber(const char *s) {bool flag;while(*s==' ')s++;const char *s2=s+strlen(s)-1;while(*s2==' '){s2--;}if(*s=='+'||*s=='-')s++; const char *s1=s;int point=0;int e=0;int count=0;while(*s1!='\0'&&s1<=s2){if(isdigit(*s1)){s1++;count++;}else if(*s1=='.'&&e==0){s1++;point++;}else if(*s1=='e'&&s1!=s&&count>=1){if(isdigit(*(s1+1))){s1=s1+2;e++;}else if((s1+2<=s2)&&(*(s1+1)=='+'||*(s1+1)=='-')){s1=s1+2;e++;}else return false;}else return false;} if(point<=1&&e<=1&&count>=1)return true;else return false;return true; }
};
转载于:https://www.cnblogs.com/tgkx1054/archive/2013/05/22/3092693.html
leetcode valid number相关推荐
- LeetCode Valid Number(判断字符串是否是合法的数字表示 )
思路: 1.如果是指数表现法,e后不能有小数 2.数字中有带有正负表示只能有一个 3.小数时点只能有一个 代码如下: public class Solution {public boolean isN ...
- LeetCode - Valid Number
题目: Validate if a given string is numeric. Some examples: "0" => true " 0.1 " ...
- [Leetcode]-- Valid Number
package validNumber;public class Solution {public boolean isNumber(String s) {if (s == null)return f ...
- 【To Do! 重点 正则表达式】LeetCode 65. Valid Number
LeetCode 65. Valid Number 本博客转载自:[1]http://www.cnblogs.com/yuzhangcmu/p/4060348.html [2]https://blog ...
- LeetCode 191 Number of 1 Bits
LeetCode 191 Number of 1 Bits 解法一(较为传统都解法):使用将n不断右移,并与1想&得到1的个数:(也有使用除法/2的,明显除法的运行效率要低于位移) 时间复杂度 ...
- LeetCode 200. Number of Islands--c++ dfs解法
LeetCode 200. Number of Islands LeetCode题解专栏:LeetCode题解 LeetCode 所有题目总结:LeetCode 所有题目总结 大部分题目C++,Pyt ...
- Valid Number
Valid Number 题解 题目描述 即判断某个字符串是否合法的数字表达式. 如: 2e10,合法. 75.0.,非法. 0e,非法. 0.1 ,合法. 题解 基于规则与状态判断.可利用二维数组模 ...
- LeetCode Singer Number
Python LeetCode Singer Number 题目说明 算法1 数学方法 算法2 异或运算 题目说明 给定一个列表,其中包含数对相同元素与一个单独元素,例如[2,2,1].[1,3,5, ...
- LeetCode——Valid Parenthese
Leetcode--Valid Parenthese #20 Given a string containing just the characters '(', ')', '{', '}', '[' ...
最新文章
- MySQL 存储过程 经常使用语法
- 利达主机联网接线端子_门禁主机接门锁和开门按钮方法
- MVC简捷调用EasyUI的datagrid
- SpringBoot-@Configuration
- 高仿真的类-BeanDefinitionReader
- Arrays.sort与Arrays.parallelSort
- matlab exist()判断目录文件是否存在
- C++基础与深度解析第八章:动态内存管理
- shell编程——判断条件
- 驱动程序和应用程序的区别_复仇者黑客组织—教你写第一个Linux设备驱动程序...
- angular之factory、service、provider
- hex2bin和bin2hex
- FA 工业自动化设备设计基础
- Review Board的几点使用体会
- 网络安全与渗透:sql注入,一文详解(九)此生无悔入华夏,男儿何不带吴钩
- 全国计算机二级flash,教你如何在Flash当中制作插按钮动画
- 图像之超简单方式实现微信头像功能
- ERROR: resetting DM9000 -> not responding dm9000 not found at 0x88000000问题解决
- 网页设计中文案是网站的性格
- C语言#define的用法,C语言宏定义
热门文章
- python文件读取数据-Python从文件中读取数据
- python常用内置模块-Python之OS模块常用内置方法汇总
- python语法大全-python基本语法
- python的none是什么-python中stream=None什么意思?
- 怎样看python源代码-如何直接从IDE读取Python源代码
- python入门指南 许半仙 txt-小九 第7章(1/1)_新笔趣阁
- python for-Python for 循环
- python自学免费课堂-python自学——文件打开
- 老师学python可以干嘛-学 Python 都用来干嘛的?
- python培训班价格-成都Python课程