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

Commit 293d1a2

Browse files
ls1248659692zengli
authored and
zengli
committed
Update leetcode_crawler.py
1 parent 26af8ed commit 293d1a2

File tree

8 files changed

+62
-7
lines changed

8 files changed

+62
-7
lines changed

‎.idea/leetcode.iml‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/misc.xml‎

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ def sliding_window_template_with_examples(s, p):
181181
>* 剑指 Offer 04. 二维数组中的查找
182182
>* 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
183183
```python3
184-
# two pointers scenario, famous applications such as binary search, quick sort and sliding window.
184+
# two pointers scenario, famous applications such as binary search, quick sort and sliding window."""
185+
# --译:双指针场景,著名的应用包括二分查找、快速排序和滑动窗口(scenario:/səˈnærioʊ/ 场景;binary:/ˈbaɪnəri/ 二进制的;quicksort:/kwɪk sɔːrt/ 快速排序;sliding:/ˈslaɪdɪŋ/ 滑动的)
185186

186187
'''
187188
Classification:

‎algorithm_templates/backtracking/backtracking.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# ("backtracks") as soon as it determines that the candidate cannot possibly be completed to a valid solution.
44
#
55
# backtracking vs. dfs
6+
# 译:回溯法与深度优先搜索
67
# traverse in solution space vs. traverse in data structure space, pruned of dfs
8+
# 译:在解空间中遍历与在数据结构空间中遍历,深度优先搜索的剪枝
79

810

911
def backtracking(self, data, candidate):

‎py_tricks/maxsplit.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#! /usr/bin/env python3
2-
"""split a string max times"""
2+
"""split a string max times -- 译:将字符串拆分最多次数(split:/spl?t/ 拆分)"""
33
string = "a_b_c"
44
print(string.split("_", 1))
55

66

7-
"""use maxsplit with arbitrarywhitespace"""
7+
"""use max split with arbitrary whitespace -- 译:使用按任意空白字符的最大拆分次数(arbitrary:/?ɑ?rb?treri/ 任意的;whitespace:/?wa?t.spe?s/ 空白字符 )"""
88

99
s = "foo bar foobar foo"
1010

‎spider/leetcode_crawler.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def get_problems_describe(self, filters=None):
142142
print('sqlite ',IS_SUCCESS)
143143
while not IS_SUCCESS and req_retry<3:
144144
# try:
145-
# 休眠随机 1 - 2 秒,以免爬去频率过高被服务器禁掉
145+
# 爬虫休眠随机 1 - 2 秒,爬取频率过高会被服务器检测到访问频率过快而禁掉ip的问题
146146
time.sleep(random.randint(1, 5))
147147
req_retry+=1
148148
cursor = conn.cursor()
@@ -577,7 +577,6 @@ def generate_questions_submission(self, path, filters):
577577
print('Specified tag is: {}'.format(args.tags))
578578

579579
leetcr.connect_mysql()
580-
581580
# leetcr.get_problems_describe()
582581
# leetcr.get_ac_questions_submission_json(filters,skipsubm=True)
583582
if args_dict.get('code'):

‎spider/problems/242-valid-anagram/README.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,33 @@ class Solution:
3232
return sorted(list(s))==sorted(list(t))
3333
```
3434

35+
36+
## 解法
37+
```python3
38+
class Solution:
39+
def isAnagram(self, s: str, t: str) -> bool:
40+
if not s or not t:
41+
return False
42+
if len(s) != len(t):
43+
return False
44+
#排序方式
45+
# return sorted(list(s)) == sorted(list(t))
46+
47+
# 字典方式:
48+
# s 和 t 仅包含小写字母 ,这里也可以通过ord返回ASCII字符对应的整数直接定义数组的方式处理
49+
s_map = dict()
50+
for c in s:
51+
s_map[c] = s_map.get(c, 0) + 1
52+
for a in t:
53+
if a not in s_map:
54+
return False
55+
else:
56+
cnt = s_map.get(a, 0) - 1
57+
s_map[a] = cnt
58+
if cnt < 0:
59+
return False
60+
return True
61+
62+
```
63+
3564
[title]: https://leetcode-cn.com/problems/valid-anagram

‎spider/problems/454-4sum-ii/README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,26 @@ l)` 能满足:
3333
**Difficulty:** Medium
3434

3535
## 思路
36+
```python3
37+
from typing import List
38+
# leetcode submit region begin(Prohibit modification and deletion)
39+
class Solution:
40+
def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:
41+
res = 0
42+
dic = {}
43+
# 计算前两个list对应的累计值字典:key:累加值,val:下标
44+
for i, a in enumerate(nums1):
45+
for j, b in enumerate(nums2):
46+
dic[a + b] = dic.get(a + b, 0) + 1
47+
# 遍历后两个数组计算,值是否存在
48+
for i, a in enumerate(nums3):
49+
for j, b in enumerate(nums4):
50+
c = 0 - a - b
51+
if c in dic and dic.get(c) > -1:
52+
# 累加时:注意,这里如果值相同,但是位置不同,算是多种组合,所以这里直接累加字典中该key的值即可
53+
res += dic.get(c)
54+
return res
55+
# leetcode submit region end(Prohibit modification and deletion)
56+
```
3657

3758
[title]: https://leetcode-cn.com/problems/4sum-ii

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /