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

Appearance settings

Latest commit

 

History

History
History
21 lines (18 loc) · 504 Bytes

File metadata and controls

21 lines (18 loc) · 504 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package ch23;
public class P94_1 {
public long calc = 0;
public int rob(int[] nums, int n) {
calc++;
if (n < 0)
return 0;
// 이전 결과와 (전전 결과 + 현재 결과) 중 큰 값 리턴
return Math.max(
rob(nums, n - 1),
rob(nums, n - 2) + nums[n]
);
}
public int rob(int[] nums) {
// 피보나치 수열 형태로 계산하여 리턴
return rob(nums, nums.length - 1);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.