【Leetcode_easy】1154. Day of the Year
problem
solution
class Solution { public: int dayOfYear(string date) { // 平年 闰年 int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int y = stoi(date.substr(0, 4)), m = stoi(date.substr(5, 2)), d = stoi(date.substr(8)); if(m>2 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) d++;//leap year..errr.. while(--m) d += days[m-1];//errr.. return d; } };
参考
1. Leetcode_easy_1154. Day of the Year;
完
各美其美,美美与共,不和他人作比较,不对他人有期待,不批判他人,不钻牛角尖。
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/