We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1e321a7 commit 82c01f1Copy full SHA for 82c01f1
โfind-minimum-in-rotated-sorted-array/hyunjung-choi.kt
@@ -0,0 +1,26 @@
1
+// ์๊ฐ ๋ณต์ก๋: O(log n)
2
+// - n: ๋ฐฐ์ด์ ๊ธธ์ด
3
+// - ๋งค ๋ฐ๋ณต๋ง๋ค ํ์ ๋ฒ์๋ฅผ ์ ๋ฐ์ผ๋ก ์ค์ด๋ ์ด์ง ํ์์ด๋ฏ๋ก O(log n)
4
+//
5
+// ๊ณต๊ฐ ๋ณต์ก๋: O(1)
6
+// - ์ถ๊ฐ์ ์ธ ๋ฐฐ์ด์ด๋ ์๋ฃ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ,
7
+// ๋ณ์(left, right, mid)๋ง ์ฌ์ฉํ๋ฏ๋ก ์์ ๊ณต๊ฐ
8
+
9
+class Solution {
10
+ fun findMin(nums: IntArray): Int {
11
+ var left = 0
12
+ var right = nums.size - 1
13
14
+ while (left < right) {
15
+ val mid = left + (right - left) / 2
16
17
+ if (nums[mid] > nums[right]) {
18
+ left = mid + 1
19
+ } else {
20
+ right = mid
21
+ }
22
23
24
+ return nums[left]
25
26
+}
0 commit comments