dsadas
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
//dfs
class Solution {
public TreeNode mirrorTree(TreeNode root) {
return dfs(root);
}
private TreeNode dfs(TreeNode node){
if(node == null)
return null;
TreeNode tmpNode = node.right;
node.right = dfs(node.left);
node.left = dfs(tmpNode);
return node;
}
}
//辅助栈
class Solution {
public TreeNode mirrorTree(TreeNode root) {
if(root == null)
return null;
//创建栈
Stack <TreeNode> stack = new Stack<>();
stack.push(root);
while(!stack.isEmpty()){
TreeNode tmpNode = stack.pop();
if(tmpNode.left!=null)
stack.push(tmpNode.left);
if(tmpNode.right!=null)
stack.push(tmpNode.right);
//开始交换
TreeNode tmpNode1 = tmpNode.left;
tmpNode.left = tmpNode.right;
tmpNode.right = tmpNode1;
}
return root;
}
}
dsadas
//有序 所以我们应该想到二分查找
class Solution {
public int missingNumber(int[] nums) {
int l = 0 , r = nums.length-1;
while(l<=r){
int mid = (l+r)/2;
if(nums[mid]==mid)
l = mid +1;
else
r = mid - 1;
}
return l;
}
}