Skip to content

Commit f918430

Browse files
committed
做了两题
1 parent 376d94c commit f918430

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

main.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,56 @@
77

88

99

10+
class Solution:
11+
12+
#3516
13+
def findClosest(self, x: int, y: int, z: int) -> int:
14+
if abs(x-z) < abs(y-z):
15+
return 1
16+
elif abs(x-z) > abs(y-z):
17+
return 2
18+
else:
19+
return 0
20+
#2749
21+
def makeTheIntegerZero(self, num1: int, num2: int) -> int:
22+
def compute(num):
23+
temp = 1
24+
while temp * 2 <= num:
25+
temp *= 2
26+
27+
accu = 0
28+
while num > 0:
29+
num -= temp
30+
accu += 1
31+
while temp > num:
32+
temp //= 2
33+
return accu
34+
35+
time = 1
36+
while True and time < 1000:
37+
if time >= compute(num1 - time * num2) and compute(num1 - time * num2) > 0 and time <= num1 - time * num2:
38+
return time
39+
time += 1
40+
return -1
41+
#845
42+
def longestMountain(self, arr):
43+
"""
44+
:type arr: List[int]
45+
:rtype: int
46+
枚举中间
47+
"""
48+
mid = 0
49+
op = 0
50+
ed = 0
51+
n = len(arr)
52+
ans = 0
53+
while mid < n:
54+
while op-1 >= 0 and arr[op-1] < arr[op]:
55+
op -= 1
56+
while ed+1 < n and arr[ed+1] < arr[ed]:
57+
ed += 1
58+
ans = max(ans, ed-op + 1)
59+
mid = ed + 1
60+
return ans
61+
62+

0 commit comments

Comments
 (0)