TLE


  • 0
    S

    '''
    public class Solution {
    public int[] twoSum(int[] numbers, int target) {
    // same number should not use twice
    int x = 0;
    int pos = 0;

      for(int i = 0 ; i< numbers.length;i++){
          
          int diff = target - numbers[i];
          
          pos = i;
          
           x = binarySearch(numbers,diff,i+1,numbers.length-1);
          
          if( x == -1){
              
              continue;
          }
          
          else {
              
              break;
          }
          
         
      }
       return new int[]{pos + 1, x + 1};
      
    }
    
    
    public int binarySearch(int[] numbers,int target ,int start,int end){
        while (start <= end) {
            int mid = start + (end - start) / 2;
            if      (target < numbers[mid]) end = mid - 1;
            else if (target > numbers[mid]) start = mid + 1;
            else return mid;
        }
        return -1;
    }
        '''
    }

Log in to reply
 

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