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 496d9e4 commit 9ddfdfbCopy full SHA for 9ddfdfb
search-in-rotated-sorted-array/yolophg.js
@@ -0,0 +1,16 @@
1
+// Time Complexity: O(n)
2
+// Space Complexity: O(1)
3
+
4
+var search = function(nums, target) {
5
+ // iterate through each element.
6
+ for (let i = 0; i < nums.length; i++) {
7
+ // check if the current element is equal to the target.
8
+ if (nums[i] === target) {
9
+ // if found, return the index.
10
+ return i;
11
+ }
12
13
14
+ // if the loop completes without finding the target, return -1.
15
+ return -1;
16
+};
0 commit comments