Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf7294be

Browse files
refactor 568
1 parent5eb30e3 commitf7294be

File tree

1 file changed

+25
-21
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+25
-21
lines changed

‎src/main/java/com/fishercoder/solutions/_568.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,31 +74,35 @@ You totally have K weeks (each week has 7 days) to travel.
7474
*/
7575
publicclass_568 {
7676

77-
/**credit: https://leetcode.com/articles/maximum-vacation-days/#approach-2-using-dfs-with-memoization-accepted*/
78-
publicintmaxVacationDays(int[][]flights,int[][]days) {
79-
int[][]memo =newint[flights.length][days[0].length];
80-
for (int[]l:memo) {
81-
Arrays.fill(l,Integer.MIN_VALUE);
77+
publicstaticclassSolution1 {
78+
/**
79+
* credit: https://leetcode.com/articles/maximum-vacation-days/#approach-2-using-dfs-with-memoization-accepted
80+
*/
81+
publicintmaxVacationDays(int[][]flights,int[][]days) {
82+
int[][]memo =newint[flights.length][days[0].length];
83+
for (int[]l :memo) {
84+
Arrays.fill(l,Integer.MIN_VALUE);
85+
}
86+
returndfs(flights,days,0,0,memo);
8287
}
83-
returndfs(flights,days,0,0,memo);
84-
}
8588

86-
publicintdfs(int[][]flights,int[][]days,intcurCity,intweekno,int[][]memo) {
87-
if (weekno ==days[0].length) {
88-
return0;
89-
}
90-
if (memo[curCity][weekno] !=Integer.MIN_VALUE) {
91-
returnmemo[curCity][weekno];
92-
}
93-
intmaxvac =0;
94-
for (inti =0;i <flights.length;i++) {
95-
if (flights[curCity][i] ==1 ||i ==curCity) {
96-
intvac =days[i][weekno] +dfs(flights,days,i,weekno +1,memo);
97-
maxvac =Math.max(maxvac,vac);
89+
publicintdfs(int[][]flights,int[][]days,intcurCity,intweekno,int[][]memo) {
90+
if (weekno ==days[0].length) {
91+
return0;
92+
}
93+
if (memo[curCity][weekno] !=Integer.MIN_VALUE) {
94+
returnmemo[curCity][weekno];
95+
}
96+
intmaxvac =0;
97+
for (inti =0;i <flights.length;i++) {
98+
if (flights[curCity][i] ==1 ||i ==curCity) {
99+
intvac =days[i][weekno] +dfs(flights,days,i,weekno +1,memo);
100+
maxvac =Math.max(maxvac,vac);
101+
}
98102
}
103+
memo[curCity][weekno] =maxvac;
104+
returnmaxvac;
99105
}
100-
memo[curCity][weekno] =maxvac;
101-
returnmaxvac;
102106
}
103107

104108
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp