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 39d8b97

Browse files
committed
129-weekly-contest-python
1 parent edcf962 commit 39d8b97

File tree

4 files changed

+68
-0
lines changed
  • solution

4 files changed

+68
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
3+
def canThreePartsEqualSum(self, A: List[int]) -> bool:
4+
"""
5+
先判断是否能被3整除,如果可以,再判断是否可以至少分割成3份
6+
"""
7+
s = sum(A)
8+
if s % 3 != 0:
9+
return False
10+
g = s / 3
11+
stack = 0
12+
c = 0
13+
for num in A:
14+
stack += num
15+
if stack == g:
16+
stack = 0
17+
c += 1
18+
return c >= 2
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
3+
def maxScoreSightseeingPair(self, A: List[int]) -> int:
4+
"""
5+
构建A[i]+i和A[j]-j两个子序列,然后从后往前遍历,最值只要遍历一遍就可以
6+
如果从前往后,时间复杂度会变大
7+
"""
8+
ai = [i + index for index, i in enumerate(A)]
9+
aj = [i - index for index, i in enumerate(A)]
10+
aj = aj[::-1]
11+
ans = 0
12+
t = float('-inf')
13+
for index, i in enumerate(ai[-2::-1]):
14+
t = max(aj[index], t)
15+
ans = max(ans, i + t)
16+
return ans
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
3+
def smallestRepunitDivByK(self, K: int) -> int:
4+
"""
5+
数学题,100000这个数,错几次就试出来了,太小会报错,太大会超时
6+
"""
7+
mod = 1
8+
for i in range(1, 100000):
9+
mod %= K
10+
if mod == 0:
11+
return i
12+
mod *= 10
13+
mod += 1
14+
return -1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
3+
def queryString(self, S: str, N: int) -> bool:
4+
"""
5+
迭代构建数字库,然后循环判断
6+
"""
7+
s = set()
8+
li = []
9+
for byte in list(S)[::-1]:
10+
i = int(byte)
11+
li[0:0] = [0]
12+
if i:
13+
li = [num + 2**index for index, num in enumerate(li)]
14+
s.update(li)
15+
for i in range(1, N + 1):
16+
if i in s:
17+
continue
18+
else:
19+
return False
20+
return True

0 commit comments

Comments
(0)

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