publicint[] findTwoSwapped(List<Integer> nums) { int n = nums.size(); int x = -1, y = -1; for(int i = 0; i < n - 1; ++i) { if (nums.get(i + 1) < nums.get(i)) { y = nums.get(i + 1); // first swap occurence if (x == -1) x = nums.get(i); // second swap occurence elsebreak; } } returnnewint[]{x, y}; }

publicvoidrecover(TreeNode r, int count, int x, int y){ if (r != null) { if (r.val == x || r.val == y) { r.val = r.val == x ? y : x; if (--count == 0) return; } recover(r.left, count, x, y); recover(r.right, count, x, y); } }