We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 593e06a commit f3a9a4aCopy full SHA for f3a9a4a
house-robber/aa601.c
@@ -0,0 +1,40 @@
1
+int rob(int* nums, int numsSize) {
2
+ int *dp;
3
+ int max;
4
+ int i;
5
+ int j;
6
+
7
+ // dp에 nums 복사
8
+ dp = malloc(sizeof(int) * numsSize);
9
+ if (!dp)
10
+ return (0);
11
+ i = -1;
12
+ while (++i < numsSize) {
13
+ dp[i] = nums[i];
14
+ }
15
16
+ // dp 시작
17
+ i = 0;
18
+ j = 0;
19
20
21
+ max = dp[i];
22
+ while (j + 1 < i) {
23
+ if (max < dp[i] + dp[j])
24
+ max = dp[i] + dp[j];
25
+ ++j;
26
27
+ dp[i] = max;
28
29
30
+ // dp 배열의 최종 max값 리턴
31
32
+ max = dp[0];
33
34
+ if (max < dp[i])
35
36
37
+ free(dp);
38
+ return (max);
39
+}
40
0 commit comments