leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 3f32877cbfeb9eaa9b4833fb7982e61d4b00e017
parent 58ae575e67fd69adda079b167c243ffbdbb54c97
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Sun, 28 May 2023 20:45:50 -0500

Completed search in rotated array with O(n) time complexity

Diffstat:
Asearch-in-rotated-array/search-in-roatated-array.dart | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/search-in-rotated-array/search-in-roatated-array.dart b/search-in-rotated-array/search-in-roatated-array.dart @@ -0,0 +1,15 @@ +//Given a rotated array find the index of the target value. +//If there are no instances then return -1. +//Time: 297ms Beats: 36% +//Memory: 143.3MB Beats: 56% + +class Solution { + int search(List<int> nums, int target) { + for(int i = 0 ; i < nums.length ; ++i){ + if(nums[i] == target){ + return i; + } + } + return -1; + } +}