首页 > 其他 > 详细

LeetCode:Valid Number

时间:2015-06-05 21:13:26      阅读:255      评论:0      收藏:0      [点我收藏+]

problem:

Validate if a given string is numeric.

Some examples:
"0" => true
" 0.1 " => true
"abc" => false
"1 a" => false
"2e10" => true

Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.

Update (2015-02-10):
The signature of the C++ function had been updated. If you still see your function signature accepts a const char * argument, please click the reload button  to reset your code definition.

 

用的STL的strtod()函数 ps:太懒

class Solution {
public:
    bool isNumber(string s) {
        const char* str=s.c_str();
        char* endptr;  
        strtod(str,&endptr);
        
        if(endptr==str) return false;
        
        for(;*endptr;++endptr)
           if(!isspace(*endptr)) return false;
        return true;
    }
};

  

LeetCode:Valid Number

原文:http://www.cnblogs.com/xiaoying1245970347/p/4555546.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!