有效数字
来源:互联网 发布:西安软件开发工资水平 编辑:程序博客网 时间:2024/04/30 23:10
给定一个字符串,验证其是否为数字。
样例
"0"
=> true
" 0.1 "
=> true
"abc"
=> false
"1 a"
=> false
"2e10"
=> true
class Solution {public: /** * @param s the string that represents a number * @return whether the string is a valid number */ bool isNumber(string& s) { // Write your code here int n = s.length(); int begin = 0; int end = n-1; while (s[begin] == ' ') { begin++; } while (s[end] == ' ') { end--; } if (begin > end) { return false; } bool dotFound = false; bool eFound = false; bool numFound = false; for (int i = begin; i <= end; i++) { if (s[i] <= '9' && s[i] >= '0') { numFound = true; continue; } else if (s[i] == '.') { if (i == end) { return false; } else if (dotFound || eFound) { return false; } else { dotFound = true; continue; } } else if (s[i] == 'e') { if (!numFound || i == end) { return false; } else if (dotFound || eFound) { return false; } else { eFound = true; continue; } } else { return false; } } return true; }};
0 0
- 有效数字
- 有效数字
- 有效数字
- input 有效数字
- float 有七位有效数字
- 华为OJ--有效数字
- 有效数字的保留
- LintCode:有效数字
- 计算器 保留有效数字
- lintcode,有效数字
- 精确到两位有效数字
- 417.有效数字
- java获取有效数字
- lintcode 有效数字
- 有效数字-LintCode
- LintCode刷题:有效数字
- 输出时保留有效数字
- 浮点数有效数字位数
- iOS NSDate比较两个时间的大小
- OpenCV2的helloworld
- 每日一算法之《贪心算法》
- MVC框架显示层——Velocity技术
- ios多线程学习之GCD线程锁
- 有效数字
- MAC下Android Studio获取MD5,SHA1
- JS 之 验证电话号码
- 直插式电阻电容封装与尺寸图解
- Android 应用实现多进程
- mysql 5.7忘记root密码
- 黑马程序员——关于单例模式的多种写法
- Leetcode 第191题 Number of 1 Bits
- Android Studio快捷键(默认设置)