码迷,mamicode.com
首页 > 其他好文 > 详细

剑指Offer 67

时间:2019-06-14 22:04:48      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:coding   self   col   else   elf   als   style   lse   class   

 1 # -*- coding:utf-8 -*-
 2 class Solution:
 3     def StrToInt(self, s):
 4         n = len(s)
 5         if n == 0:
 6             return 0
 7         isNegative =  False
 8         if s[0] == -:
 9             isNegative = True
10         ret = 0
11         for i in range(n):
12             c = s[i]
13             if i == 0 and (c == + or c == -):
14                 continue
15             if c < 0 or c >9:
16                 return 0
17             ret = ret * 10 + (ord(c) - ord(0))
18         return -ret if isNegative else ret
19         # write code here

 

剑指Offer 67

标签:coding   self   col   else   elf   als   style   lse   class   

原文地址:https://www.cnblogs.com/asenyang/p/11025328.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!