-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6416476
commit 0d7ccc4
Showing
6 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Solution: | ||
def maxProfit(self, prices: List[int]) -> int: | ||
result = 0 | ||
|
||
for i in range(len(prices) - 1): | ||
if prices[i+1] > prices[i]: | ||
result += prices[i+1] - prices[i] | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Solution: | ||
def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int: | ||
if sum(gas) < sum(cost): | ||
return -1 | ||
|
||
|
||
start, fuel = 0, 0 | ||
for i in range(len(gas)): | ||
if gas[i] + fuel < cost[i]: | ||
start = i + 1 | ||
fuel = 0 | ||
else: | ||
fuel += gas[i] - cost[i] | ||
|
||
return start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import re | ||
import collections | ||
import itertools | ||
import heapq | ||
import bisect | ||
|
||
class Solution: | ||
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]: | ||
result = [] | ||
heap = [] | ||
|
||
for person in people: | ||
heapq.heappush(heap, (-person[0], person[1])) | ||
|
||
|
||
while heap: | ||
person = heapq.heappop(heap) | ||
result.insert(person[1], (-person[0], person[1])) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Solution: | ||
def characterReplacement(self, s: str, k: int) -> int: | ||
left = right = 0 | ||
|
||
counts = collections.Counter() | ||
|
||
for right in range(1, len(s) + 1): | ||
|
||
counts[s[right-1]] += 1 | ||
|
||
max_char_n = counts.most_common(1)[0][1] | ||
|
||
if right - left - max_char_n > k: | ||
counts[s[left]] -= 1 | ||
left += 1 | ||
|
||
return right - left |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Solution: | ||
def findContentChildren(self, g: List[int], s: List[int]) -> int: | ||
g.sort() | ||
s.sort() | ||
|
||
i = j = 0 | ||
|
||
while i < len(g) and j < len(s): | ||
if g[i] <= s[j]: | ||
i += 1 | ||
j += 1 | ||
|
||
return i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import re | ||
import collections | ||
import itertools | ||
import heapq | ||
import bisect | ||
|
||
class Solution: | ||
def minWindow(self, s: str, t: str) -> str: | ||
need = collections.Counter(t) | ||
missing = len(t) | ||
left = start = end = 0 | ||
|
||
for right, char in enumerate(s, 1): | ||
missing -= need[char] > 0 | ||
need[char] -= 1 | ||
|
||
if missing == 0: | ||
|
||
while left < right and need[s[left]] < 0: | ||
need[s[left]] += 1 | ||
left += 1 | ||
|
||
if not end or right - left <= end - start: | ||
start, end = left, right | ||
|
||
# need[s[left]] += 1 | ||
# missing += 1 | ||
# left += 1 | ||
|
||
return s[start:end] |