Leetcode 3175. Find The First Player to win K Games in a Row

1. 解题思路

这一题我的解答比较暴力,基本就是暴力解答,唯一优化的就是对于特殊情况进行了一下剪枝,具体来说的话,如果k大于长度n,那么显然最后首先达到胜利条件的一定是最大的那个元素,而对于其他的情况,我就暴力求解了。

2. 代码实现

给出python代码实现如下:

class Solution:
    def findWinningPlayer(self, skills: List[int], k: int) -> int:
        players = [[skill, i, 0] for i, skill in enumerate(skills)]
        if k >= len(players):
            return max(players)[1]
        while players[0][2] < k:
            if players[0][0] < players[1][0]:
                players[1][2] += 1
                players.append(players.pop(0))
            else:
                players[0][2] += 1
                players.append(players.pop(1))
        return players[0][1]

提交代码评测得到:耗时7429ms,占用内存37.3MB。

相关推荐

  1. leetcode周赛375 - 12 - 10

    2024-06-12 02:32:02       45 阅读
  2. Leetcode 3175. Find The First Player to win K Games in a Row

    2024-06-12 02:32:02       12 阅读
  3. Leetcode 3145. Find Products of Elements of Big Array

    2024-06-12 02:32:02       10 阅读
  4. Leetcode 3171. Find Subarray With Bitwise AND Closest to K

    2024-06-12 02:32:02       10 阅读
  5. Leetcode375场周赛,个人题解

    2024-06-12 02:32:02       29 阅读
  6. Leetcode315题:计算右侧小于当前元素的个数

    2024-06-12 02:32:02       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-12 02:32:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-12 02:32:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-12 02:32:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-12 02:32:02       18 阅读

热门阅读

  1. Flask-REXTx 学习笔记——2.字段掩码(Fields masks)

    2024-06-12 02:32:02       10 阅读
  2. Qt6 播放音视频

    2024-06-12 02:32:02       11 阅读
  3. 嵌入式常用工具

    2024-06-12 02:32:02       9 阅读
  4. 高效 “Phone Call” 策略获得更多订单!

    2024-06-12 02:32:02       9 阅读
  5. 第一章 - 第6节- 数制转换 - 课后习题

    2024-06-12 02:32:02       12 阅读
  6. MyQueue(队列)

    2024-06-12 02:32:02       13 阅读
  7. 下载黄金投资软件的正确方法及注意事项

    2024-06-12 02:32:02       9 阅读