GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/python/065_Valid_Number.py at master · alex0freeman/leetcode Expand file tree/ Copy path065_Valid_Number.pyMore file actions 52 lines (51 loc) · 1.47 KB / Copy path065_Valid_Number.pyFile metadata and controls52 lines (51 loc) · 1.47 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 class Solution(object): # def isNumber(self, s): # """ # :type s: str # :rtype: bool # """ # # remove lead and tail space # s = s.strip() # try: # float(s) # return True # except: # if '.' in s or ' ' in s: # return False # temp = s.split('e') # if len(temp) == 2: # try: # int(temp[0]) # int(temp[1]) # except: # return False # return True # return False def isNumber(self, s): s = s.strip() ls, pos = len(s), 0 if ls == 0: return False if s[pos] == '+' or s[pos] == '-': pos += 1 isNumeric = False while pos < ls and s[pos].isdigit(): pos += 1 isNumeric = True if pos < ls and s[pos] == '.': pos += 1 while pos < ls and s[pos].isdigit(): pos += 1 isNumeric = True elif pos < ls and s[pos] == 'e' and isNumeric: isNumeric = False pos += 1 if pos < ls and (s[pos] == '+' or s[pos] == '-'): pos += 1 while pos < ls and s[pos].isdigit(): pos += 1 isNumeric = True print pos, ls, isNumeric if pos == ls and isNumeric: return True return False |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |