上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 33 下一页
摘要: 我是将链表转成了数组,然后就变成和108题是一样的了。 但是效果并不是很好。 public TreeNode sortedListToBST(ListNode head) { ArrayList<Integer> list = new ArrayList<>(); if(head == null) 阅读全文
posted @ 2020-07-02 11:07 欣姐姐 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 不是我自己写出来的,思想大概是懂的,没自己写,看了别人的代码; public List<TreeNode> generateTrees(int n) { if(n == 0){ return new LinkedList<>(); } return generate_trees(1,n); } pr 阅读全文
posted @ 2020-07-01 21:27 欣姐姐 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 还可以,自己做得出来。 public TreeNode buildTree(int[] inorder, int[] postorder) { //用一个map来存储中序 int n = inorder.length; if(n == 0){ return null; }else if(n == 1 阅读全文
posted @ 2020-07-01 20:09 欣姐姐 阅读(173) 评论(0) 推荐(0) 编辑
摘要: public Node connect(Node root) { if(root == null){ return root; } Queue<Node> Q = new LinkedList<>(); Q.add(root); while (Q.size() > 0){ int size = Q. 阅读全文
posted @ 2020-07-01 17:21 欣姐姐 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 先中序遍历,对中序遍历得到的数组进行排序,将排序之后的数组与排序之前的数组比较,就可以找到是哪两个数进行了交换。 再中序遍历二叉树进行节点的值的交换,得到结果。 但是写得不够简洁,性能并不怎么样。 public void recoverTree(TreeNode root) { ArrayList< 阅读全文
posted @ 2020-07-01 11:28 欣姐姐 阅读(149) 评论(0) 推荐(0) 编辑
摘要: public List<List<Integer>> zigzagLevelOrder(TreeNode root) { if(root == null){ return new ArrayList<>(); } List<List<Integer>> results = new ArrayList 阅读全文
posted @ 2020-07-01 10:02 欣姐姐 阅读(194) 评论(0) 推荐(0) 编辑
摘要: public List<List<Integer>> levelOrderBottom(TreeNode root) { LinkedList<List<Integer>> res = new LinkedList<>(); if(root == null){ return res; } Queue 阅读全文
posted @ 2020-06-30 16:29 欣姐姐 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 这道题自己完成的,不难。 回溯。 public boolean exist(char[][] board, String word) { int m = board.length; int n = board[0].length; int wordLength = word.length(); if 阅读全文
posted @ 2020-06-30 10:56 欣姐姐 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 看了大佬的题解,茅塞顿开 public void solveSudoku(char[][] board) { if(board == null || board.length != 9 || board[0] == null || board[0].length != 9){ return; } b 阅读全文
posted @ 2020-06-30 10:08 欣姐姐 阅读(122) 评论(0) 推荐(0) 编辑
摘要: public List<String> restoreIpAddresses(String s) { int len = s.length(); List<String> res = new ArrayList<>(); if(len<4 ||len>12) { return res; } Dequ 阅读全文
posted @ 2020-06-29 10:06 欣姐姐 阅读(129) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 33 下一页