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 ac05c98 commit 43f4b16Copy full SHA for 43f4b16
โlongest-increasing-subsequence/Tessa1217.java
@@ -0,0 +1,27 @@
1
+/**
2
+ * ์ ์ ๋ฐฐ์ด nums๊ฐ ์ฃผ์ด์ง ๋ ๊ฐ์ฅ ๊ธธ๊ฒ ์ฆ๊ฐํ๋ ๋ถ๋ถ ์์ด์ ๊ธธ์ด๋ฅผ ์ฐพ์ผ์ธ์. (LIS)
3
+ */
4
+class Solution {
5
+
6
+ // ์๊ฐ๋ณต์ก๋: O(n^2)
7
+ public int lengthOfLIS(int[] nums) {
8
9
+ int[] dp = new int[nums.length];
10
+ int n = nums.length;
11
+ int max = 0;
12
13
+ // ์์์ ์์น์์ ๊ฐ์ง ์ ์๋ LIS์ ๊ฐ ๊ณ์ฐ
14
+ for (int i = 0; i < n; i++) {
15
+ dp[i] = 1;
16
+ for (int j = 0; j < i; j++) {
17
+ if (nums[j] < nums[i]) {
18
+ dp[i] = Math.max(dp[i], dp[j] + 1);
19
+ }
20
21
+ max = Math.max(dp[i], max);
22
23
24
+ return max;
25
26
+}
27
0 commit comments