Skip to content

Commit 926e8a0

Browse files
committed
update
1 parent 4aa2954 commit 926e8a0

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
***给定两个字符串 s 和 p,找到 s 中所有 p 的 异位词 的子串,返回这些子串的起始索引。不考虑答案输出的顺序。***
2+
3+
```
4+
class Solution(object):
5+
def findAnagrams(self, s, p):
6+
"""
7+
:type s: str
8+
:type p: str
9+
:rtype: List[int]
10+
"""
11+
n = len(s)
12+
res = []
13+
left = 0
14+
cnt = [0]*26
15+
16+
target = [0]*26
17+
for c in p:
18+
target[ord(c)-ord('a')] += 1
19+
20+
for i in range(n):
21+
cnt[ord(s[i])-ord('a')] += 1
22+
if i >= len(p):
23+
cnt[ord(s[left])-ord('a')] -= 1
24+
left += 1
25+
if cnt == target:
26+
res.append(left)
27+
return res
28+
```

93. 和为s的连续正数序列.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
***输入一个正整数 target ,输出所有和为 target 的连续正整数序列(至少含有两个数)。***
2+
3+
```
4+
class Solution:
5+
def findContinuousSequence(self, target: int) -> List[List[int]]:
6+
i, j, s, res = 1, 2, 3, []
7+
while i<j:
8+
if s == target:
9+
res.append(list(range(i,j+1)))
10+
s-=i
11+
i+=1
12+
elif s>target:
13+
s-=i
14+
i+=1
15+
else:
16+
j+=1
17+
s+=j
18+
return res
19+
```

0 commit comments

Comments
 (0)