Learn SAS from the best-SAS Base, Advanced, and Predictive Modeling

Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

You must write an algorithm with O(log n) runtime complexity.

Solution:

class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
for i in range(len(nums)):
if(nums[i]>=target):
return i
return len(nums)

By RichS

2 thoughts on “Leetcode Question and Solution”

Leave a Reply

Your email address will not be published. Required fields are marked *


Fatal error: Uncaught wfWAFStorageFileException: Unable to save temporary file for atomic writing. in /home/beasjrbr/quantfinanc.com/wp-content/plugins/wordfence/vendor/wordfence/wf-waf/src/lib/storage/file.php:34 Stack trace: #0 /home/beasjrbr/quantfinanc.com/wp-content/plugins/wordfence/vendor/wordfence/wf-waf/src/lib/storage/file.php(658): wfWAFStorageFile::atomicFilePutContents('/home/beasjrbr/...', '<?php exit('Acc...') #1 [internal function]: wfWAFStorageFile->saveConfig('livewaf') #2 {main} thrown in /home/beasjrbr/quantfinanc.com/wp-content/plugins/wordfence/vendor/wordfence/wf-waf/src/lib/storage/file.php on line 34