代码如下: classSolution(object):defdayOfTheWeek(self, day, month, year):""":type day: int :type month: int :type year: int :rtype: str"""week= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]importdatetime whatday= datetime.datetime(year, month, day).strf...
https://github.com/grandyang/leetcode/issues/1185 参考资料: https://leetcode.com/problems/day-of-the-week/ https://leetcode.com/problems/day-of-the-week/discuss/377384/JavaC%2B%2BPython-Zeller-Formula https://leetcode.com/problems/day-of-the-week/discuss/381894/JavaC%2B%2BPython3-Sakamo...
https:///grandyang/leetcode/issues/1185 参考资料: https://leetcode.com/problems/day-of-the-week/ https://leetcode.com/problems/day-of-the-week/discuss/377384/JavaC%2B%2BPython-Zeller-Formula https://leetcode.com/problems/day-of-the-week/discuss/381894/JavaC%2B%2BPython3-Sakamoto-Algorith...
* public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public int diameterOfBinaryTree(TreeNode root) { if (root==null){ return 0; } return Math.max(Math.max(diameterOfBinaryTree(root.left),diameterOf...
https://leetcode.cn/problems/subarray-sum-equals-k/solution/python3-by-wu-qiong-sheng-gao-de-qia-non-w6jw/ classSolution:defsubarraySum(self,nums:List[int],k:int)->int:# 要求的连续子数组count=0n=len(nums)preSums=dict()preSums[0]=1presum=0foriinrange(n):presum+=nums[i]count+=pr...
https://leetcode.cn/problems/minimum-path-sum/solution/zui-xiao-lu-jing-he-by-leetcode-solution/ class Solution:defminPathSum(self,grid:List[List[int]])->int:ifnot grid or not grid[0]:return0rows,columns=len(grid),len(grid[0])dp=[[0]*columnsfor_inrange(rows)]dp[0][0]=grid[0...
LeetCode 174. 地下城游戏[1] 题目描述 一些恶魔抓住了公主(P)并将她关在了地下城的右下角。地下城是由 M x N 个房间组成的二维网格。我们英勇的骑士(K)最初被安置在左上角的房间里,他必须穿过地下城并通过对抗恶魔来拯救公主。 骑士的初始健康点数为一个正整数。如果他的健康点数在某一时刻降至 0 或以...
They included the markup language for code blocks in the code itself and said “ope, i guess the code doesn’t work lol” when leetcode failed to run it. They also *only* included prime numbers in their dataset when asking ChatGPT if the numbers were prime or not, resulting in both ...
LeetCode 72. 编辑距离[1] 题目描述 给你两个单词 word1 和word2,请你计算出将 word1 转换成 word2 所使用的最少操作数 。 你可以对一个单词进行如下三种操作: 插入一个字符 删除一个字符 替换一个字符 示例1 代码语言:javascript 代码运行次数:0 运行 AI代码解释输入...
Leetcode刷题——day2 class Solution { public int thirdMax(int[] nums) { int n = nums.length; long first, second, third; first = second = third = Long.MIN_VALUE; if(n == 1) return nums[0]; if(n == 2) return Math.max(nums[0], nums[1]);...