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 c5c6b04 commit fde8195Copy full SHA for fde8195
house-robber/sungjinwi.c
@@ -0,0 +1,35 @@
1
+#include <stdlib.h>
2
+#include <stdio.h>
3
+
4
+/*
5
+ 시간복잡도
6
7
+ 이중for문
8
+ => O(N^2)
9
10
+ 공간복잡도
11
12
+ dp만큼 malloc
13
+ => O(N)
14
+*/
15
16
+int rob(int* nums, int numsSize) {
17
+ int *dp;
18
+ int max_before;
19
+ int max = 0;
20
21
+ dp = malloc(numsSize * sizeof(int));
22
+ for (int i = 0; i < numsSize; i++)
23
+ {
24
+ max_before = 0;
25
+ for (int j = 0; j < i - 1; j++)
26
+ if (dp[j] > max_before)
27
+ max_before = dp[j];
28
+ dp[i] = nums[i] + max_before;
29
+ }
30
31
+ if (dp[i] > max)
32
+ max = dp[i];
33
+ free(dp);
34
+ return (max);
35
+}
0 commit comments