摘要:
题目链接 解题思路:从后往前遍历,模拟即可 代码 class Solution: def plusOne(self, digits: List[int]) -> List[int]: # 直接在原数组上改 carry = 1 for i in range(len(digits) - 1, -1, - 阅读全文
posted @ 2024-12-22 19:51
ouyangxx
阅读(13)
评论(0)
推荐(0)
摘要:
题目链接 解题思路:数学题,一共要走m + n - 2步,选择其中的n - 1往右走,或者选择其中的m - 1往下走,就是C(n-1)/(n+m-2) 代码 class Solution: def uniquePaths(self, m: int, n: int) -> int: # 计算C(m - 阅读全文
posted @ 2024-12-22 19:41
ouyangxx
阅读(8)
评论(0)
推荐(0)
摘要:
题目链接 解题思路:按照第一维度排序,然后依次遍历,假设现在遍历到i,[begin1, end1],然后i+1是[begin2, end],如果begin2 <= end1,那么二者可以合并成[begin1, max(end1, end2)],因为按照第一维度排序的,所以开头是begin1,结尾注意 阅读全文
posted @ 2024-12-22 19:33
ouyangxx
阅读(18)
评论(0)
推荐(0)
摘要:
题目链接 解题思路:初始能够到达最远的位置max_index是nums[0],然后我们就依次遍历i <= nums[0],然后途中不断更新max_index,如果更新到某一时刻,到达了最后一个下标,返回true,如果「走不动」了,那么就返回false 代码 class Solution: def c 阅读全文
posted @ 2024-12-22 15:49
ouyangxx
阅读(19)
评论(0)
推荐(0)
摘要:
题目链接 解题思路:宏观思路,一圈一圈打,确定好「一圈」的左上角以及右下角,然后再打印。有两种特殊情况,左上角和右上角的列相等时,只需要打一行即可;左上角的列和右下角的列相等时,只需打印一列即可。 代码: from typing import List class Solution: def spi 阅读全文
posted @ 2024-12-22 15:22
ouyangxx
阅读(16)
评论(0)
推荐(0)

浙公网安备 33010602011771号