标签:solution bsp int not class else rip string break
def solution(s): s=s.strip() if(s): l=len(s) first_n=-1 b_n=-1 last_n=-1 f_n=-1 for i in range(l): if(s[i].isdigit()): first_n=i continue if(not s[i].isdigit()): if(s[i]=="."): f_n=1 continue if(i==0): if(s[i]=="-"): b_n=i continue elif(s[i]=="+"): b_n=i continue else: return 0 else: if(s[i]=="-"): b_n=i continue elif(s[i]=="+"): b_n=i continue last_n=i break print(first_n,last_n,f_n,b_n) if(s[0]=="-"): if(first_n==-1): return 0 x=s[b_n:first_n+1] elif(s[0]=="+"): x=s[b_n:first_n+1] else: if(last_n==-1): x=s[:] else: x=s[0:last_n] if(b_n==0 and first_n==-1 and last_n==-1): return 0 print(f_n) if(not f_n==-1): if(("-" in s) and (("+") in s)): return 0 print(x) x=float(x) else: x=int(x) if(x>2147483647): return 0 elif(x<-2147483647): return 0 else: return x else: return 0 s="+-2" print("k",solution(s))
标签:solution bsp int not class else rip string break
原文地址:https://www.cnblogs.com/sea-stream/p/10503598.html