Find First and Last Position of Element in Sorted Array LeetCode solution in Java

1
class Solution {
2
public int[] searchRange(int[] nums, int target) {
3
int first = -1, last = -1;
4
for (int i = 0; i < nums.length; i++) {
5
if (nums[i] == target) {
6
if (first == -1) {
7
first = i;
8
}
9
last = i;
10
}
11
}
12
return new int[] {first, last};
13
}
14
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0