java:
简单题重拳出击
还是看了题解 笑
parseInt() 方法用于将字符串参数作为有符号的十进制整数进行解析
class Solution {
public int dayOfYear(String date) {
int year = Integer.parseInt(date.substring(0, 4));
int month = Integer.parseInt(date.substring(5, 7));
int day = Integer.parseInt(date.substring(8));
int[] each_m = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0 )){
++each_m[1];
}
int res = 0;
for(int i = 0; i < month-1; i++){
res += each_m[i];
}
return res+day;
}
}