일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- LeetCode
- DWG
- Generator
- shiba
- 파이썬
- Python
- Protocol
- concurrency
- 프로그래머스
- 시바견
- 운영체제
- Regular Expression
- Class
- Decorator
- 밴픽
- iterator
- 43. Multiply Strings
- Python Implementation
- Python Code
- attribute
- Substring with Concatenation of All Words
- 109. Convert Sorted List to Binary Search Tree
- 컴퓨터의 구조
- 715. Range Module
- Convert Sorted List to Binary Search Tree
- 30. Substring with Concatenation of All Words
- data science
- 315. Count of Smaller Numbers After Self
- kaggle
- t1
Archives
- Today
- Total
Scribbling
LeetCode: 334. Increasing Triplet Subsequence 본문
Computer Science/Coding Test
LeetCode: 334. Increasing Triplet Subsequence
focalpoint 2022. 1. 11. 20:38This problem is a special case of #300, which is LIS.
Refer to LIS algorithm here.
https://focalpoint.tistory.com/179
LeetCode: 300. Longest Increasing Subsequence - 시바견의 끄적임
1. 가장 간단한 DP 형태 O(N**2)이다. class Solution: def lengthOfLIS(self, nums: List[int]) -> int: dp = [0] * len(nums) dp[0] = 1 for i in range(1, len(nums)): temp = -1 j = i - 1 while j >= 0: if n..
focalpoint.tistory.com
class Solution:
def increasingTriplet(self, nums: List[int]) -> bool:
dp = [nums[0]]
for i in range(1, len(nums)):
num = nums[i]
insert_flag = False
for j in range(len(dp)):
if num <= dp[j]:
dp[j] = num
insert_flag = True
break
if not insert_flag:
dp.append(num)
if len(dp) == 3:
return True
return False
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 378. Kth Smallest Element in a Sorted Matrix (0) | 2022.01.14 |
---|---|
LeetCode: 341. Flatten Nested List Iterator (0) | 2022.01.13 |
LeetCode: 329. Longest Increasing Path in a Matrix (0) | 2022.01.11 |
LeetCode: 350. Intersection of Two Arrays II (0) | 2022.01.10 |
LeetCode: 322. Coin Change (0) | 2022.01.07 |