Runtime:20 ms, faster than99.51% of Python3 online submissions for Day of the Year. Memory Usage:13.8 MB, less than52.20% of Python3 online submissions for Day of the Year. 简洁一点的写法 classSolution:defdayOfYear(self, date: str) ->int: y, m, d= map(int, date.split('-')) ...
【leetcode】1154. Day of the Year 题目如下: Given a stringdaterepresenting aGregorian calendardate formatted asYYYY-MM-DD, return the day number of the year. Example 1: Input: date = "2019-01-09" Output: 9 Explanation: Given date is the 9th day of the year in 2019. Example 2: Inpu...
1. Leetcode_easy_1154. Day of the Year; 完
return days[(year + (year / 4 - year / 100 + year / 400) + t[month - 1] + day) % 7]; } }; 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Github 同步地址: https:///grandyang/leetcode/issues/1185 参考资料: https://leetcode.com/problems/day-of-the-week/ https://leetcode.co...
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...
return0nc=len(grid[0])num_islands=0forrinrange(nr):forcinrange(nc):ifgrid[r][c]=="1":num_islands+=1self.dfs(grid,r,c)returnnum_islands 作者:LeetCode链接:https://leetcode.cn/problems/number-of-islands/solutions/13103/dao-yu-shu-liang-by-leetcode/来源:力扣(LeetCode) 著作权归作者...
1.题目:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s. 2. 01背包问题c++实现 leetcode腾讯精选009 题目:https://leetcode-cn.com/problems/palindrome-number/ 代码: class Solution { publi...
提示: date.length == 10 date[4] == date[7] == ‘-’,其它的 date 都是数字 代码语言:javascript 代码运行次数:0 运行 AI代码解释 classSolution{publicintdayOfYear(String date){int totalDays=0;int year=Integer.parseInt(date.substring(0,4));int month=Integer.parseInt(date.substring(5,7));...
// Sakamoto Algorithm class Solution { public: string dayOfTheWeek(int day, int month, int year) { vector<string> days{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; vector<int> t{0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; if (month < ...
}if(month >2&& (year %400==0|| (year %100!=0&& year %4==0))) { ++res; }returnres + day; } }; Github 同步地址: https://github.com/grandyang/leetcode/issues/1154 参考资料: https://leetcode.com/problems/day-of-the-year/ ...