Error in :Given a sorted array 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.


  • 0

    '''
    class Solution(object):
    def searchInsert(self, nums, target):
    """
    :type nums: List[int]
    :type target: int
    :rtype: int
    """

        print target
        print nums
        for i in nums:
            print i
            if i==target:
                return nums.index(i)
                
            else:
                for i in nums:
                    if i>=target:
                        nums.append('target')
                        
                    else:
                        nums.append('target')
                        
                print False
    

    '''

    I think I solved the first part but I am struggling to make second part of appending work. Can anyone guide ?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.