Skip to content

Commit dba3561

Browse files
add .py
1 parent b722783 commit dba3561

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

058_Length of Last Word.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def lengthOfLastWord(self, s):
3+
"""
4+
:type s: str
5+
:rtype: int
6+
"""
7+
l = len(s)
8+
if 0 == l:
9+
return 0
10+
j = 0
11+
s = s[::-1]
12+
for i in range(0,l):
13+
if s[i] != ' ':
14+
j += 1
15+
else:
16+
if j != 0:
17+
break
18+
else:
19+
continue
20+
return j

066_Plus One.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def plusOne(self, digits):
3+
"""
4+
:type digits: List[int]
5+
:rtype: List[int]
6+
"""
7+
l = len(digits)
8+
digits[l - 1] += 1
9+
for i in range(l - 1, -1, -1):
10+
if 10 == digits[i]:
11+
if i == 0:
12+
digits[i] = 0
13+
digits.insert(0,1)
14+
else:
15+
digits[i] = 0
16+
digits[i - 1] += 1
17+
return digits

069(Func)_ Sqrt(x).py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def mySqrt(self, x):
3+
"""
4+
:type x: int
5+
:rtype: int
6+
"""
7+
import math
8+
return int(math.sqrt(x))

0 commit comments

Comments
 (0)