๋ชฉ์ฐจ
LeetCode - Problems - Algorithms - 300. Longest Increasing Subsequence
Problem Description
Given an integer array nums, return the length of the longest strictly increasing subsequence.
Example:

Constraints:

My Solution (C#)
public int LengthOfLIS(int[] nums)
{
int numsLength = nums.Length;
int[] maxSubsequenceLengths = new int[numsLength];
Array.Fill(maxSubsequenceLengths, 1); //maxSubsequenceLengths[i]๋ 0๋ถํฐ [i]๊น์ง๋ฅผ ๋น๊ตํ์ ๋ ์ต์ฅ ์์ด ๊ธธ์ด.
for(int i = 1; i < numsLength; i++)
{
for (int j = 0; j < i; j++)
{
if (nums[i] > nums[j])
{
maxSubsequenceLengths[i] = Math.Max(maxSubsequenceLengths[i], maxSubsequenceLengths[j] + 1);
}
}
}
return maxSubsequenceLengths.Max();
}
๋์ ํ๋ก๊ทธ๋๋ฐ์ผ๋ก ์งํํด์ผํ๋ค.
๋ ๋น ๋ฅด๊ฒ ์งํํ ์ ์๋ ํ์ด๊ฐ ์๋ ๊ฒ ๊ฐ์๋ฐ ์ด ๋ถ๋ถ์ ๋์ค์ ์งํํด๋ด์ผ๊ฒ ๋ค.
์ ํ๋ธ ํด์ค์ ๋ด๋ ์ดํด๊ฐ ์ ๋งคํด์.. ์ด์ฐ์ ์ฐ ํ๊ธด ํ๋๋ฐ, ์ด๊ฒ ๋์ ํ๋ก๊ทธ๋๋ฐ ์์ฒด์ ๋ํ ์ดํด๋๋ฅผ ๋ํ๋ ๊ฑด ์๋์๋ค.
์กฐ๊ธ ๋ ์ฌ์ด ๋์ด๋๋ก ๋์ ํ๋ก๊ทธ๋๋ฐ์ ์ดํดํ๊ณ ์ ์ฉํ ์ ์๋ ๋ฌธ์ ๋ฅผ ๋ช๊ฐ์ง ๋ ํ์ด๋ด์ผ๊ฒ ๋ค...
'Problem solving > Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [ํ๋ก๊ทธ๋๋จธ์ค] ์ฝ์ ๊ตฌํ๊ธฐ (C#) (0) | 2025.07.17 |
|---|---|
| [ํ๋ก๊ทธ๋๋จธ์ค] ์์ฐ์ ๋ค์ง์ด ๋ฐฐ์ด๋ก ๋ง๋ค๊ธฐ (C#) (0) | 2025.07.15 |
| [ํ๋ก๊ทธ๋๋จธ์ค]์ต๋๊ฐ๊ณผ ์ต์๊ฐ (C#) (0) | 2025.07.11 |
| [LeetCode] 733. Flood Fill (C#)๏ปฟ (0) | 2025.07.09 |
| [ํ๋ก๊ทธ๋๋จธ์ค]์ฝ์์ ํฉ (C#) (0) | 2025.07.08 |