(String[] args)
| 2 | |
| 3 | public class Leetcode34 { |
| 4 | public static void main(String[] args) { |
| 5 | int[] arr={2,5,7,9,9,9,9,10,12,16}; |
| 6 | int target=9; |
| 7 | int first=search(arr,target,true); |
| 8 | int last=search(arr,target,false); |
| 9 | System.out.println("First Occurence At="+first); |
| 10 | System.out.println("Last Occurence At="+last); |
| 11 | |
| 12 | } |
| 13 | |
| 14 | static int search(int[] arr, int target,boolean isStart){ |
| 15 | int start=0,end=arr.length-1;int ans=-1; |