Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions jump-game/evan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def canJump(nums):
n = len(nums)
dp = [False] * n
dp[0] = True

for i in range(n):
if dp[i]:
maxJump = min(i + nums[i], n - 1)

for j in range(i + 1, maxJump + 1):
dp[j] = True

return dp[n - 1]
18 changes: 18 additions & 0 deletions longest-common-subsequence/evan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
def longestCommonSubsequence(self, text1, text2):
text1_length, text2_length = len(text1), len(text2)
# dp[i][j]는 text1의 처음 i 글자와 text2의 처음 j 글자의 LCS 길이를 의미합니다.
dp = [[0] * (text2_length + 1) for _ in range(text1_length + 1)]

for text1_char in range(1, text1_length + 1):
for text2_char in range(1, text2_length + 1):
if text1[text1_char - 1] == text2[text2_char - 1]:
# 두 문자가 같으면 그 이전까지의 LCS 길이에 1을 더한 값으로 현재 위치를 갱신합니다.
dp[text1_char][text2_char] = dp[text1_char - 1][text2_char - 1] + 1
else:
# 두 문자가 다르면 이전까지의 최대 LCS 길이 중 더 큰 값을 현재 위치에 저장합니다.
dp[text1_char][text2_char] = max(
dp[text1_char - 1][text2_char], dp[text1_char][text2_char - 1]
)

return dp[text1_length][text2_length]
19 changes: 19 additions & 0 deletions longest-increasing-subsequence/evan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import bisect
from typing import List


class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
lis = []

for num in nums:
# num이 왼쪽에 삽입될 수 있는 위치
position = bisect.bisect_left(lis, num)

# num이 lis에 있는 모든 요소 보다 크다
if position == len(lis):
lis.append(num)
else:
lis[position] = num

return len(lis)
13 changes: 13 additions & 0 deletions maximum-subarray/evan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import List


class Solution:
def maxSubArray(self, nums: List[int]) -> int:
global_max_sum = nums[0]
local_max_sum = nums[0]

for num in nums[1:]:
local_max_sum = max(num, local_max_sum + num)
global_max_sum = max(global_max_sum, local_max_sum)

return global_max_sum
10 changes: 10 additions & 0 deletions unique-paths/evan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
dp = [[1] * n for _ in range(m)]

# Iterate over the grid starting from 1,1 to fill the number of unique paths for each cell
for i in range(1, m):
for j in range(1, n):
dp[i][j] = dp[i - 1][j] + dp[i][j - 1]

return dp[m - 1][n - 1]