Another simple accepted method


  • -13
    H
    public class Solution {
        public int searchInsert(int[] A, int target) {
            int pos = 0;
            for(int i = 0; i < A.length; i++){
                if (A[i] >= target){
                    pos = i;
                    break;
                 }
                 pos = A.length;
               }
            
            return pos;
        }
    }

  • 4
    S

    This solution is too straight forward. The time complexity is O(N). There is a O(log N) solution by using the binary search.


Log in to reply
 

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