File tree 6 files changed +70
-5
lines changed
6 files changed +70
-5
lines changed Original file line number Diff line number Diff line change 1
1
# 「LeetCode-Python3习题集」使用说明
2
2
3
- [ ![ HitCount] ( http://hits.dwyl.io/ML-ZimingMeng/https://githubcom/ML-ZimingMeng/ LeetCode-Python3.svg )] ( http://hits.dwyl.io/ML-ZimingMeng/https://githubcom /ML-ZimingMeng/LeetCode-Python3 ) [ ![ GitHub forks] ( https://img.shields.io/github/forks/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/network ) [ ![ GitHub stars] ( https://img.shields.io/github/stars/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/stargazers ) [ ![ GitHub license] ( https://img.shields.io/github/license/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/blob/master/LICENSE )
3
+ [ ![ HitCount] ( http://hits.dwyl.io/ML-ZimingMeng/LeetCode-Python3.svg )] ( http://hits.dwyl.io/ML-ZimingMeng/LeetCode-Python3 ) [ ![ GitHub forks] ( https://img.shields.io/github/forks/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/network ) [ ![ GitHub stars] ( https://img.shields.io/github/stars/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/stargazers ) [ ![ GitHub license] ( https://img.shields.io/github/license/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/blob/master/LICENSE )
4
4
5
5
[ usEnglish Document] ( README_en.md ) | 中文说明
6
6
## 简介
45
45
## 结尾
46
46
- 利用 Python 爬虫获取自己的 LeetCode 提交代码,并上传到 Github,请 [ 点击这里] ( https://github.com/ML-ZimingMeng/LeetCodeCN-Submissions-Crawler ) 。
47
47
- 为了带来最佳的阅读体验,本文遵循[ 「中文文案排版指北」] ( https://github.com/mzlogin/chinese-copywriting-guidelines ) 。
48
- - 更多 Markdown 语法,请查看 [ 官方文档] ( https://www.markdownguide.org/basic-syntax/ ) 。
49
48
- 感谢您阅读「LeetCode-Python3习题集」使用说明,祝您刷题愉快!
Original file line number Diff line number Diff line change 1
1
# "LeetCode-Python3 Notebook" Problem Solutions
2
2
3
- [ ![ HitCount] ( http://hits.dwyl.io/ML-ZimingMeng/https://githubcom/ML-ZimingMeng/ LeetCode-Python3.svg )] ( http://hits.dwyl.io/ML-ZimingMeng/https://githubcom /ML-ZimingMeng/LeetCode-Python3 ) [ ![ GitHub forks] ( https://img.shields.io/github/forks/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/network ) [ ![ GitHub stars] ( https://img.shields.io/github/stars/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/stargazers ) [ ![ GitHub license] ( https://img.shields.io/github/license/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/blob/master/LICENSE )
3
+ [ ![ HitCount] ( http://hits.dwyl.io/ML-ZimingMeng/LeetCode-Python3.svg )] ( http://hits.dwyl.io/ML-ZimingMeng/LeetCode-Python3 ) [ ![ GitHub forks] ( https://img.shields.io/github/forks/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/network ) [ ![ GitHub stars] ( https://img.shields.io/github/stars/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/stargazers ) [ ![ GitHub license] ( https://img.shields.io/github/license/ML-ZimingMeng/LeetCode-Python3 )] ( https://github.com/ML-ZimingMeng/LeetCode-Python3/blob/master/LICENSE )
4
4
5
5
usEnglish Document | [ 中文说明] ( README.md )
6
6
## Introduction
@@ -35,13 +35,12 @@ usEnglish Document | [中文说明](README.md)
35
35
- [ Design] ( /source/Clarification/Design )
36
36
### 2. Classified by Order
37
37
- [ No.1 - No.1340] ( /source/All_Solutions )
38
- - [ 周赛 & 双周赛 ] ( /source/weeks )
38
+ - [ Weekly Contests ] ( /source/weeks )
39
39
> If it is helpful, your ✨Star will be my great honor.^_ ^
40
40
## About
41
41
- Blog:[ ziming.xyz] ( https://www.ziming.xyz/ )
42
42
- My LeetCode:[ Pumpkin🎃] ( https://leetcode-cn.com/u/ml-zimingmeng/ )
43
43
- Wechat: 🔰925730493
44
44
- Get your own LeetCode submission code in one click and upload it to Github, [ click here] ( https://github.com/ML-ZimingMeng/LeetCodeCN-Submissions-Crawler ) .
45
45
- In order to bring the best reading experience, this article follows[ 「中文文案排版指北」] ( https://github.com/mzlogin/chinese-copywriting-guidelines ) .
46
- - For more Markdown syntax, please see [ Official Documentation] ( https://www.markdownguide.org/basic-syntax/ ) .
47
46
- Thank you for reading the "LeetCode-Python3 Problem Solutions" instruction manual, and I wish you a happy reading!
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def kWeakestRows (self , mat : List [List [int ]], k : int ) -> List [int ]:
3
+ dic = {}
4
+ for i in range (len (mat )):
5
+ dic [i ] = mat [i ].count (1 )
6
+ sort_dic = sorted (dic .items (),key = lambda x :x [1 ])
7
+ res = []
8
+ i = 0
9
+ for key ,value in sort_dic :
10
+ res .append (key )
11
+ i += 1
12
+ if i == k :
13
+ break
14
+ return res
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def minSetSize (self , arr : List [int ]) -> int :
3
+ from collections import Counter
4
+ n = len (arr )
5
+ dic = Counter (arr )
6
+ sorted_dic = sorted (dic .items (),key = lambda x :x [1 ],reverse = True )
7
+ ans = 0
8
+ for num , count in sorted_dic :
9
+ n -= count
10
+ ans += 1
11
+ if n <= len (arr ) / 2 :
12
+ break
13
+ return ans
Original file line number Diff line number Diff line change
1
+ # Definition for a binary tree node.
2
+ # class TreeNode:
3
+ # def __init__(self, x):
4
+ # self.val = x
5
+ # self.left = None
6
+ # self.right = None
7
+
8
+ class Solution :
9
+ def maxProduct (self , root : TreeNode ) -> int :
10
+ def getSum (root ):
11
+ if not root :
12
+ return 0
13
+ ret = getSum (root .left ) + getSum (root .right ) + root .val
14
+ hashmap [root ] = ret
15
+ return ret
16
+ hashmap = {}
17
+ totalSum = getSum (root )
18
+ ans = 0
19
+ for k in hashmap :
20
+ ans = max (ans ,(totalSum - hashmap [k ]) * hashmap [k ])
21
+ return ans % (10 ** 9 + 7 )
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def maxJumps (self , arr : List [int ], d : int ) -> int :
3
+ D = {}
4
+ l = len (arr )
5
+ def P (n ):
6
+ if n in D :
7
+ return D [n ]
8
+ t = 1
9
+ for i in range (1 ,d + 1 ):
10
+ if n + i >= l or arr [n ] <= arr [n + i ]:
11
+ break
12
+ t = max (t , 1 + P (n + i ))
13
+ for i in range (1 , d + 1 ):
14
+ if n - i < 0 or arr [n ] <= arr [n - i ]:
15
+ break
16
+ t = max (t , 1 + P (n - i ))
17
+ D [n ] = t
18
+ return t
19
+ return max (P (i ) for i in range (l ))
You can’t perform that action at this time.
0 commit comments