We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 78d6982 commit e5a0ff0Copy full SHA for e5a0ff0
1 file changed
12015.py
@@ -0,0 +1,29 @@
1
+# 가장 긴 증가하는 부분 수열 2
2
+# Binary Search, Stack
3
+
4
+N = int(input())
5
+A = list(map(int, input().split()))
6
7
+stack = []
8
9
10
+def binarySearch(arr, start, end, target):
11
+ if (start >= end):
12
+ return start
13
+ mid = (start + end) // 2
14
15
+ if (arr[mid] == target):
16
+ return mid
17
+ if (arr[mid] < target):
18
+ return binarySearch(arr, mid+1, end, target)
19
+ return binarySearch(arr, start, mid, target)
20
21
22
+for a in A:
23
+ if not stack or (stack[-1] < a):
24
+ stack.append(a)
25
+ else:
26
+ i = binarySearch(stack, 0, len(stack), a)
27
+ stack[i] = a
28
29
+print(len(stack))
0 commit comments