-
[LeetCode] 65. Valid NumberLife/PS 2026. 5. 31. 19:11

There is some duplicates between function isInteger and isDecimal. But, in this time, I won;t be handle it.
class Solution { public: static inline bool isDigit(char ch) { return '0' <= ch && ch <= '9'; } bool isInteger(string s) { int i = 0, len = s.length(); bool digit = false; if (len <= 0) { return false; } if (s[0] == '+' || s[0] == '-') { i++; } for(; i < len; i++) { if (!isDigit(s[i])) { return false; } digit = true; } return digit; } bool isDecimal(string s) { int i = 0, len = s.length(); bool digit = false, dot = false; if (len <= 0) { return false; } if (s[0] == '+' || s[0] == '-') { i++; } for(; i < len; i++) { if (s[i] == '.') { if (dot) { return false; } else { dot = true; continue; } } if (!isDigit(s[i])) { return false; } digit = true; } return digit; } bool isNumber(string s) { int exponent = s.find('e'); if (exponent == -1) { exponent = s.find('E'); } if (exponent == -1) { return isDecimal(s); } return isDecimal(s.substr(0, exponent)) && isInteger(s.substr(exponent+1)); } };'Life > PS' 카테고리의 다른 글
[LeetCode] 76. Minimum Window Substring (0) 2026.06.07 [LeetCode] 68. Text Justification (0) 2026.06.04 [LeetCode] 60. Permutation Sequence (0) 2026.05.30 [LeetCode] 52. N-Queens II (0) 2026.05.29 [LeetCode] 51. N-Queens (0) 2026.05.29