Skip to content

Commit 53d11bc

Browse files
author
wuduhren
committed
updates
1 parent 881c58d commit 53d11bc

5 files changed

+80
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int]) -> int:
3+
minPrice = prices[0]
4+
ans = 0
5+
6+
for i in range(1, len(prices)):
7+
ans = max(ans, prices[i]-minPrice)
8+
minPrice = min(prices[i], minPrice)
9+
10+
return ans
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def longestConsecutive(self, nums: List[int]) -> int:
3+
numSet = set(nums)
4+
ans = 0
5+
6+
for num in nums:
7+
isStart = num-1 not in numSet
8+
if isStart:
9+
count = 0
10+
temp = num
11+
while temp in numSet:
12+
count += 1
13+
temp += 1
14+
ans = max(count, ans)
15+
return ans
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def characterReplacement(self, s: str, k: int) -> int:
3+
counter = collections.Counter()
4+
l = 0
5+
ans = 0
6+
7+
for r in range(len(s)):
8+
counter[s[r]] += 1
9+
while (r-l+1)-max(counter.values()) > k:
10+
counter[s[l]] -= 1
11+
l += 1
12+
ans = max(ans, r-l+1)
13+
return ans
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def lengthOfLongestSubstring(self, s: str) -> int:
3+
ans = 0
4+
l = 0
5+
seen = set()
6+
7+
for r in range(len(s)):
8+
while s[r] in seen:
9+
seen.remove(s[l])
10+
l += 1
11+
seen.add(s[r])
12+
ans = max(ans, r-l+1)
13+
14+
return ans
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution:
2+
def checkInclusion(self, s1: str, s2: str) -> bool:
3+
if len(s1)>len(s2): return False
4+
5+
counter1 = collections.Counter(s1)
6+
counter2 = collections.Counter(s2[:len(s1)])
7+
matches = 0
8+
for c in 'abcdefghijklmnopqrstuvwxyz':
9+
if counter1[c]==counter2[c]: matches += 1
10+
if matches==26: return True
11+
12+
l = 0
13+
for r in range(len(s1), len(s2)):
14+
counter2[s2[r]] += 1
15+
if counter1[s2[r]]==counter2[s2[r]]:
16+
matches += 1
17+
elif counter1[s2[r]]+1==counter2[s2[r]]:
18+
matches -= 1
19+
20+
counter2[s2[l]] -= 1
21+
if counter1[s2[l]]==counter2[s2[l]]:
22+
matches += 1
23+
elif counter1[s2[l]]-1==counter2[s2[l]]:
24+
matches -= 1
25+
l += 1
26+
27+
if matches==26: return True
28+
return False

0 commit comments

Comments
 (0)