Easiest Java Solution


  • 0
    T

    public class Solution {
    public int[] searchRange(int[] nums, int target) {
    int[] rest = {-1,-1};
    for(int i = 0; i < nums.length; i++){
    if (target == nums[i]){
    rest[0] = i;
    while ( i < nums.length && target == nums[i] ){
    rest[1] = i++;
    }
    break;
    }
    }
    return rest;
    }
    }


Log in to reply
 

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