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 e624b6a commit b009b13Copy full SHA for b009b13
search-in-rotated-sorted-array/sunjae95.js
@@ -0,0 +1,22 @@
1
+/**
2
+ * @description
3
+ * https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/
4
+ * n = length of nums
5
+ * time complexity: O(n)
6
+ * space complexity: O(1)
7
+ */
8
+var search = function (nums, target) {
9
+ let [start, end] = [0, nums.length - 1];
10
+ let answer = -1;
11
+
12
+ while (start !== end) {
13
+ if (nums[start] === target) answer = start;
14
+ if (nums[end] === target) answer = end;
15
+ if (nums[start] > nums[end]) end--;
16
+ else start++;
17
+ }
18
19
20
21
+ return answer;
22
+};
0 commit comments