Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdeea10f

Browse files
committed
重新整理LeetCode面试题系列代码.
1 parentf7666ea commitdeea10f

File tree

7 files changed

+82
-2
lines changed

7 files changed

+82
-2
lines changed

‎README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1-
#leetcode-python
2-
Python玩转LeetCode系列文章代码
1+
#Python玩转LeetCode
2+
Python 玩转 LeetCode 的学习之路
3+
4+
-[Python 玩转 LeetCode 面试题](http://www.justdopython.com/category/#/Leetcode面试题)
5+
-[Leetcode 面试系列 第1天:Leetcode 89 - 格雷码](http://www.justdopython.com/2019/09/09/python-leetcode89-gary-code/)
6+
-[LeetCode 面试系列 第2天:No.136 - 只出现一次的数](http://www.justdopython.com/2019/09/13/python-leetcode136-single-number/)
7+
-[LeetCode 面试系列 第3天:No.67 - 二进制数求和](http://www.justdopython.com/2019/09/14/python-leetcode67-add-binary/)
8+
-[LeetCode 面试系列 第4天:No.202 - 快乐数](http://www.justdopython.com/2019/09/28/python-leetcode202-happy-number/)
9+
-[LeetCode 面试系列 第5天:No.204 - 统计质数](http://www.justdopython.com/2019/10/04/python-leetcode204-count-primes/)
10+
11+
关注公众号:python技术,回复"python"一起学习交流
12+
13+
![](http://favorites.ren/assets/images/python.jpg)

‎leetcode-067/leetcode67.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
classSolution:
2+
defaddBinary(self,a:str,b:str)->str:
3+
num1=int(a,2)
4+
num2=int(b,2)
5+
sum0=num1+num2
6+
returnformat(sum0,'b')
7+
8+
# 测试
9+
sol=Solution()
10+
print(sol.addBinary('11','1101'))

‎leetcode-089/leetcode89.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fromtypingimportList
2+
3+
classSolution:
4+
defgrayCode(self,n:int)->List[int]:
5+
res= []
6+
foriinrange(1<<n):
7+
res.append((i>>1)^i)
8+
returnres
9+
10+
# Below is testing
11+
obj=Solution()
12+
print(obj.grayCode(2))

‎leetcode-136/leetcode136-method1.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
fromtypingimportList
2+
3+
classSolution:
4+
defsingleNumber(self,nums:List[int])->int:
5+
res=0
6+
d=dict()
7+
fornuminnums:
8+
ifnumnotind:
9+
d[num]=1
10+
else:
11+
d[num]+=1
12+
res=next(kfork,valind.items()ifval==1)
13+
returnres
14+
15+
#以下是测试
16+
sol=Solution()
17+
print(sol.singleNumber([6,4,6,2,4]))

‎leetcode-136/solution-method2.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fromtypingimportList
2+
3+
classSolution:
4+
defsingleNumber(self,nums:List[int])->int:
5+
r=0
6+
foriinnums:
7+
r^=i
8+
returnr
9+
10+
#以下是测试
11+
sol=Solution()
12+
print(sol.singleNumber([6,4,6,2,4]))

‎leetcode-202/leetcode202.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
classSolution:
2+
defisHappy(self,n:int)->bool:
3+
unhappy=set()
4+
whilennotinunhappyandn!=1:
5+
unhappy.add(n)
6+
n=self.GetSquareSum(n)
7+
returnn==1
8+
9+
defGetSquareSum(self,n:int)->bool:
10+
sum0=0
11+
whilen>0:
12+
r=n-int(n/10)*10
13+
n=int(n/10)
14+
sum0+=r*r
15+
returnsum0
16+
17+
sol=Solution()
18+
print(sol.isHappy(19))

‎leetcode-204/leetcode204-method1.py

Whitespace-only changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp