Skip to content

Commit fec324a

Browse files
authored
Merge pull request #67 from zhanary/master
Update solution 014 [Python2]-20ms
2 parents 8e4c094 + b0fadbd commit fec324a

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

Solution2.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution(object):
2+
def longestCommonPrefix(self, strs):
3+
if not strs:
4+
return ""
5+
for i,group in enumerate(zip(*strs)):#把字符串变成一个字母一个字母的格式
6+
if len(set(group))>1: #集合里多于一个字符
7+
return strs[0][:i] #输出0到目前编号位的字符
8+
else:
9+
return min(strs) #其他情况
10+

solution/001.Two Sum/Solution2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#time 32ms
1+
#time 32ms with python2
22
class Solution(object):
33
def twoSum(self, nums, target):
44
buff = {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#36ms with python2
2+
class Solution:
3+
def reverse(self, x):
4+
s = cmp(x,0) #提取此输入数字的符号
5+
r = int(`x*s`[::-1]) #先作为字符串输入,然后转回整型
6+
return r*s * (r<2**31) #防止溢出,小于的情况下返回true,否则为false
7+
8+

solution/013.Roman to Integer/Solution2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# 80ms with python2
12
class Solution(object):
23
def romanToInt(self, s):
34
dict = {'M':1000, 'D':500, 'C':100, 'L':50, 'X':10, 'V':5, 'I':1} #对应关系存在一个字典里

0 commit comments

Comments
 (0)