摘要: 暴力法: class Solution { public int majorityElement(int[] nums) { //最容易想到暴力法 int n = nums.length; if(n==1) return nums[0]; Map<Integer,Integer> map = new 阅读全文
posted @ 2020-08-20 16:06 欣姐姐 阅读(116) 评论(0) 推荐(0)
摘要: public String[] permutation(String s) { //显然是递归加回溯 char[] c = s.toCharArray(); int n = c.length; //可能有重复元素,所以用set来存储, Set<String> set = new HashSet<>( 阅读全文
posted @ 2020-08-20 14:55 欣姐姐 阅读(95) 评论(0) 推荐(0)
摘要: class Solution { Node pre, head; public Node treeToDoublyList(Node root) { if(root == null) return null; dfs(root); head.left = pre; pre.right = head; 阅读全文
posted @ 2020-08-20 10:02 欣姐姐 阅读(94) 评论(0) 推荐(0)
摘要: // Encodes a tree to a single string. public String serialize(TreeNode root) { if(root == null) return "[]"; Deque<TreeNode> deque = new LinkedList<>( 阅读全文
posted @ 2020-08-20 10:01 欣姐姐 阅读(118) 评论(0) 推荐(0)