This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
TreeNode a = null, b = null, pre = null; | |
public void recoverTree(TreeNode root) { | |
if (root == null) | |
return; | |
recover(root); | |
TreeNode temp = new TreeNode(0); | |
temp.val = a.val; | |
a.val = b.val; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Time complexity O(nlogn), Space complexity O(1) */ | |
class Solution1{ | |
boolean isPerm(String s1, String s2){ | |
if(s1==null||s2==null) return false; | |
if(s1.length()!=s2.length()) return false; | |
char[] arr1 = s1.toCharArray(); | |
char[] arr2 = s2.toCharArray(); | |
Arrays.sort(arr1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Solution 1: | |
Brute force. | |
Complexity: O(n^2) | |
Space complexity O(1) | |
*/ | |
public class Solution1{ | |
boolean isUnique(String str){ | |
// boundary condition | |
if(str==null||str=="") return true; |