leetcode刷题 54 55

    xiaoxiao2021-04-15  295

    class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: result = [] while matrix and matrix[0]: if matrix[0]: result += matrix.pop(0) if matrix and matrix[0]: for row in matrix: result.append(row.pop()) if matrix and matrix[-1]: result += matrix.pop()[::-1] if matrix and matrix[0]: for row in matrix[::-1]: result.append(row.pop(0)) return result

    class Solution: def canJump(self, nums: List[int]) -> bool: farthest = nums[0] for i in range(len(nums)): if i <= farthest: farthest = max(i+nums[i], farthest) return len(nums)-1 <= farthest 刘润森! 认证博客专家 Python Java 前端 17年就读于东莞XX学院化学工程与工艺专业,GitChat作者。Runsen的微信公众号是"Python之王",因为Python入了IT的坑,从此不能自拔。公众号内容涉及Python,Java计算机、杂谈。干货与情怀同在。喜欢的微信搜索:「Python之王」。个人微信号:RunsenLiu。不关注我公号一律拉黑!!!

    最新回复(0)