My Java Solution

  • 0

    Below is my solution,

            public class Solution {
              public int[] searchRange(int[] nums, int target) {
                    int start=0;
                    int end=nums.length-1;
                   int[] result={-1,-1};
            while(nums[start]<target && start<nums.length-1) start++;
            while(nums[end]>target && end>0) end--;
            if(target==nums[start] && target!=nums[end]){result[0]=start; result[1]=start; return result;}
            if(target==nums[start] && target==nums[end]){result[0]=start; result[1]=end; return result;}
            if(target==nums[end] && target!=nums[start]){result[0]=end; result[1]=end; return result;}
       return result;


Log in to reply

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