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.
2 parents ac37548 + d3e60bd commit 2ca8100Copy full SHA for 2ca8100
紀錄/24 20210406.md
@@ -47,6 +47,21 @@ func findPeakElement(_ nums: [Int]) -> Int {
47
return low
48
}
49
```
50
+```Swift
51
+// 想說用recursive做看看 但發現好像只能抓到 Peak Element 不能找到當初的Index
52
+func findPeakElement(_ nums: [Int]) -> Int {
53
+ func helper(_ low: Int, _ high: Int) -> Int {
54
+ if low >= high {return low}
55
+ let pivot = (high - low) / 2 + low
56
+ if nums[pivot] > nums[pivot + 1] {
57
+ return helper(low, pivot)
58
+ } else {
59
+ return helper(pivot + 1, high)
60
+ }
61
62
+ return helper(0, nums.count - 1)
63
64
+```
65
* MEDIUM 153 Find Minimum in Rotated Sorted Array https://leetcode.com/problems/find-minimum-in-rotated-sorted-array
66
* Template III
67
* Article Binary Search Template III
0 commit comments