Longest Increasing Subsequence - LeetCode
Can you solve this real interview question? Longest Increasing Subsequence - Given an integer array nums, return the length of the longest strictly increasing subsequence. Example 1: Input: nums = [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest
leetcode.com
List가 주어졌을때, List에서 숫자가 오름차순 중에서 제일 긴 길이를 구하는것이다.
이틀 전, 이진탐색을 공부하면서 써먹을 수 있겠다는 생각이 들었다.
https://baseballgrammer.tistory.com/88
5일차 - 이진 탐색
순차 탐색(Sequential Search) 리스트 안에 있는 특정한 데이터를 찾기 위해 앞에서부터 데이터를 하나씩 차례대로 확인하는 방법이다. 프로그래밍언어를 배우는데 많이 실습 해봤을 탐색이다. 이진
baseballgrammer.tistory.com
Python에서는 이진탐색을 할 수 있는 라이브러리인 bisect를 사용할 수 있다.
class Solution:
def lengthOfLIS(self, nums: List[int]) -> int:
answer = []
for num in nums:
i = bisect_left(answer, num)
if i == len(answer):
answer.append(num)
else:
answer[i] = num
return len(answer)
[LeetCode][Python] 1235. Maximum Profit in Job Scheduling (0) | 2024.01.06 |
---|---|
[Programmers][Python] 캐시 (0) | 2024.01.05 |
[Programmers][Python] 의상 (0) | 2024.01.04 |
[LeetCode][Python]2870. Minimum Number of Operations to Make Array Empty (0) | 2024.01.04 |
[LeetCode][Python]2125. Number of Laser Beams in a Bank (1) | 2024.01.04 |
댓글 영역