/* t: O(n), s: O(n)*/classSolution {publicint[] sortedSquares(int[] A) {int len =A.length;int left =0;int right = len -1;int[] result =newint[len]; //must create a new array to save, or it'll be wrongfor(int i = len -1; i >=0; i--) {int leftVal =A[left]*A[left];int rightVal =A[right]*A[right];if (leftVal > rightVal) {A[i] = leftVal; left++; } else {A[i] = rightVal; right--; } }return A; }}