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 aacc968

Browse files
author
Navy.Tian
committed
add weekly-contest 380
1 parent 6e9cc44 commit aacc968

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

‎weekly-contest/380/p1_3005.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from collections import Counter
2+
from typing import List
3+
4+
5+
class Solution:
6+
def maxFrequencyElements(self, nums: List[int]) -> int:
7+
counter = Counter(nums)
8+
_, times = counter.most_common(1)[0]
9+
return sum(value for key, value in counter.items() if value == times)
10+
11+
12+
if __name__ == "__main__":
13+
assert Solution().maxFrequencyElements(nums=[1, 2, 4]) == 3
14+
assert Solution().maxFrequencyElements(nums=[1, 2, 2, 3, 1, 4]) == 4
15+
assert Solution().maxFrequencyElements(nums=[1, 2, 3, 4, 5]) == 5

‎weekly-contest/380/p2_3006.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]:
6+
a_indexes = self._find_all_indexes(s, a)
7+
b_indexes = self._find_all_indexes(s, b)
8+
ans = []
9+
for a_index in a_indexes:
10+
if self._find_abs_in_k(a_index, b_indexes, k):
11+
ans.append(a_index)
12+
return ans
13+
14+
def _find_abs_in_k(self, a_index, b_indexes, k):
15+
for b_index in b_indexes:
16+
if abs(a_index - b_index) <= k:
17+
return True
18+
return False
19+
20+
def _find_all_indexes(self, text: str, substring: str):
21+
indexes = []
22+
start = 0
23+
24+
while True:
25+
try:
26+
index = text.index(substring, start)
27+
indexes.append(index)
28+
start = index + 1
29+
except ValueError:
30+
break
31+
32+
return indexes
33+
34+
35+
if __name__ == "__main__":
36+
assert Solution().beautifulIndices(s="isawsquirrelnearmysquirrelhouseohmy", a="my", b="squirrel", k=15) == [16, 33]
37+
assert Solution().beautifulIndices(s="abcd", a="a", b="a", k=4) == [0]

‎weekly-contest/380/p3_3007.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def findMaximumNumber(self, k: int, x: int) -> int:
3+
# TODO
4+
...
5+
6+
7+
if __name__ == "__main__":
8+
assert Solution().findMaximumNumber(k=9, x=1) == 6
9+
assert Solution().findMaximumNumber(k=7, x=2) == 9

‎weekly-contest/380/p4_3008.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]:
6+
# TODO
7+
...
8+
9+
10+
if __name__ == "__main__":
11+
assert Solution().beautifulIndices(s="isawsquirrelnearmysquirrelhouseohmy", a="my", b="squirrel", k=15) == [16, 33]
12+
assert Solution().beautifulIndices(s="abcd", a="a", b="a", k=4) == [0]

0 commit comments

Comments
(0)

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