avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

1801-1803 Liech buckle novice!

  2024-01-01        
字数统计: 427字   |   阅读时长: 2min

Just write a question every day,然后写下能让自己看懂的answer吧!
The new year has passed5All over,Write this at one time5God。

first of all1801.1802.1803,The daily questions of these three days are actually a high -quality weekly match last year,Even the simple label is also ordinary difficulty。

If the method is solved, it is a stack of a triangle,Stop increased after reaching the boundary(If it continues to increase, it will lead to timeout) 。

When both sides are reached,Just lay all the remaining bricks directly on the top layer。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
1802. Specify the maximum value of the lower bid in the bounded array
medium
182
company
Amazon
company
Facebook
Give you three positive integers n、index and maxSum 。You need to construct an array that meets all the conditions at the same time nums(Bidding from 0 start count):

nums.length == n
nums[i] yes Positive integer ,in 0 <= i < n
abs(nums[i] - nums[i+1]) <= 1 ,in 0 <= i < n-1
nums 中所有元素之and不超过 maxSum
nums[index] Value maximize
Return to the array you constructed nums[index] 。

Notice:abs(x) equal x 的前提yes x >= 0 ;otherwise,abs(x) equal -x 。



Exemplary example 1:

enter:n = 4, index = 2, maxSum = 6
Output:2
explain:Array [1,1,2,1] and [1,2,2,1] Meet all conditions。不存在其他在指定BiddingPlace具有更大值的有效Array。
Exemplary example 2:

enter:n = 6, index = 1, maxSum = 10
Output:3


hint:

1 <= n <= maxSum <= 109
0 <= index < n
[]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
def maxValue(self, n: int, index: int, maxSum: int) -> int:
diff = maxSum - n
left = index
right = index
res = 1
dl = 0
dr = 0
while diff > 0: # When there are remaining bricks
left -= 1
right += 1
if left >= 0:
dl = dl + 1 # Before reaching the left boundary
if right < n:
dr = dr + 1 # Have not arrived at the right boundary
if left < 0 and right >= n: # 当到达左边界and右边界时 Exit
# res+=diff%n==0?diff/n:diff/n+1 #Divide the remaining bricks,Exit directly
res += diff // n if diff % n == 0 else diff // n + 1
return res
res += 1 # Layer renewal
diff -= (dl + dr + 1) # The number of bricks needed to strictly pile the top layer into strict triangle(On the left+Need to be on the right+indexPlace1indivual)

return res

  • Python
  • solved,answer

扫一扫,分享到微信

微信分享二维码
1814. Statistics the number of good pairs in an array One question daily
1813. Sentence similarity III
目录
ahoh, this article has no catalog.

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号