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

One question daily 2293. Great mini game

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

Although it is a simple question,But there are recursive ideas。

Constantly convert the one -dimensional list into a two -dimensional list for operation(This can be avoidedindexChaos caused by changes)

Then useflagCount,Comparison of maximum and minimum values。

Just return to the end,Although it must be returned to a number,Still‘nums[0]’To avoid warning。

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
36
37
38
39
40
41
42
2293. Great mini game
Simple
39
company
Google Google
Give you a bidding 0 Started integer array nums ,Its length is 2 Power。

right nums Execute the following algorithm:

set up n equal nums length,if n == 1 ,termination Algorithm。otherwise,create A new integer array newNums ,The length of the new array is n / 2 ,Bidding from 0 start。
right于满足 0 <= i < n / 2 Every even Bidding i ,Will newNums[i] Assignment for min(nums[2 * i], nums[2 * i + 1]) 。
right于满足 0 <= i < n / 2 Every odd number Bidding i ,Will newNums[i] Assignment for max(nums[2 * i], nums[2 * i + 1]) 。
use newNums replace nums 。
From steps 1 start repeat the whole process。
After executing the algorithm,return nums The remaining numbers。



Exemplary example 1:



enter:nums = [1,3,5,2,4,8,2,2]
Output:1
explain:repeat执行算法会得到下述数组。
first round:nums = [1,5,4,2]
second round:nums = [1,4]
Third round:nums = [1]
1 Is the last number left,return 1 。
Exemplary example 2:

enter:nums = [3]
Output:3
explain:3 Is the last number left,return 3 。


hint:

1 <= nums.length <= 1024
1 <= nums[i] <= 109
nums.length yes 2 Power

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
def minMaxGame(self, nums: List[int]) -> int:
flag = 0
while len(nums) > 1:
nums = [nums[i:i + 2] for i in range(0, len(nums), 2)]
# Divide2dimension
for i in range(len(nums)):
if flag % 2 == 0:
nums[i] = min(nums[i])
flag += 1
else:
nums[i] = max(nums[i])
flag += 1
return nums[0]

  • Python
  • solved,answer

扫一扫,分享到微信

微信分享二维码
One question daily 2283
2303. Calculate the total taxable amount
目录
ahoh, this article has no catalog.

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