Current streak:
0 days
Longest streak:
41 days
Less
More
public class Solution {
public static void mirrorTree(BinaryTreeNode node) {
// Write your code here.
if(node==null) return;
if(node!=null){
BinaryTreeNode temp=node.left;
node.left=node.right;
node.right=temp;
}
mirrorTree(node.left);
mirrorTree(node.right);
}
}
public class Solution {
public static int[] searchRange(int []arr, int x) {
// Write your code here.
int ans[]=new int[2];
int fo=-1;
int lo=-1;
int s=0;
int l=arr.length-1;
int mid=0;
while(s<=l){
mid=(s+l)/2;
if(x>arr[mid]) s=mid+1;
else if(x<arr[mid]) l=mid-1;
else{
if(arr[s]==x&&arr[l]==x){
fo=s;
lo=l;
break;
}
else if(arr[s]==x){
fo=s;
l--;
}
else{
lo=l;
s++;}
}
}
ans[0]=fo;
ans[1]=lo;
return ans;
}
}