Skip to content

Latest commit

 

History

History
23 lines (22 loc) · 557 Bytes

1154. Day of the Year.md

File metadata and controls

23 lines (22 loc) · 557 Bytes

题目

1154. Day of the Year

思路

4ms 69.67%

代码

class Solution {
public:
    int dayOfYear(string date) {
        vector<int> v={0,31,28,31,30,31,30,31,31,30,31,30,31};
        int year=stoi(date.substr(0,4));
        int month=stoi(date.substr(5,2));
        int day=stoi(date.substr(8,2));
        int ans=day;
        for(int i=0;i<month;i++){
            ans+=v[i];
        }
        if(year%4==0&&(year%100!=0||year%400==0)&&month>2)ans++;
        return ans;
    }
};