题目描述:
给你 root1 和 root2 这两棵二叉搜索树。
请你返回一个列表,其中包含 两棵树 中的所有整数并按 升序 排序。.
输入:
root1 = [2,1,4], root2 = [1,0,3]
root1 = [0,-10,10], root2 = [5,1,7,0,2]
root1 = [], root2 = [5,1,7,0,2]
root1 = [0,-10,10], root2 = []
输出:
[0,1,1,2,3,4]
[-10,0,0,1,2,5,7,10]
[0,1,2,5,7]
[-10,0,10]
题意:
题目描述
题解:
按题意模拟,用一个栈去记录
代码:
class Solution {
public int[] sortedSquares(int[] A) {
int len = A.length;
for(int i = 0; i < len; i ++){
A[i] = A[i] * A[i];
}
Arrays.sort(A);
return A;
}
}