- 博客(31)
- 收藏
- 关注
转载 数据结构全部复习
Linear Structure Array: the length cannot changed ArrayList: 当到达max length时候需要进行resize:1.5x new ArrayList & copy the old...
2017-10-06 09:45:00 148
转载 Shell Sort
How do we design the step with increment? a[i+1] = 3 * a[i] + 1 or a[i+1] = 2 * a[i] + 1 public static void shellSort(int[] nums){ int l...
2017-10-02 04:50:00 62
转载 Insertion Sort
让外循环从1开始,倒着往前进行循环 public static void insertionSort(int[] nums){ for(int i = 1; i<nums.length; i++){ for(int j = i; j > 0...
2017-10-02 04:00:00 51
转载 Selection Sort
选择排序主要是选出一个最小的,然后和后面所有的值比较直到找出最小的哪一个,最后再进行swap int smallest; public void selectionSort(int[] nums){ for(int i=0; i< nums.leng...
2017-10-02 03:24:00 69
转载 Bubble Sort
冒泡排序属于linear sorting,从头到尾遍历直到外层循环完全走完 class Solution{ public void BubbleSort(int[] nums){ for(int i=0; i<nums.length; i++){ ...
2017-10-02 03:10:00 73
转载 450. Delete Node in BST
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(i...
2017-09-22 03:45:00 92
转载 110. Balanced Binary Tree
class Solution { public boolean isBalanced(TreeNode root) { return dfsHelper(root) != -1; } public int dfsHelper(TreeNode ...
2017-09-22 03:02:00 53
转载 104. Maximum Depth of Binary Tree
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(i...
2017-09-22 02:35:00 52
转载 113. Path Sum II
一定要记住每次走到最后要把path最后一个Node删除 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * Tree...
2017-09-22 02:14:00 45
转载 112. Path Sum
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(i...
2017-09-22 01:42:00 49
转载 226. Invert Binary Tree
class Solution { public TreeNode invertTree(TreeNode root) { if (root == null){ return root; } Tre...
2017-09-20 04:30:00 47
转载 101. Symmetric Tree
class Solution { public boolean isSymmetric(TreeNode root) { if (root == null){ return true; } Que...
2017-09-19 00:36:00 50
转载 230. Kth Smallest Element in a BST
class Solution { public int kthSmallest(TreeNode root, int k) { if (root == null){ return -1; } ...
2017-09-18 13:21:00 56
转载 285. Inorder Successor in BST
思路:如果遇到比目标大的就记录下来作为潜在的successor,如果不是就直接跳过 //Iteration class Solution { public TreeNode inorderSuccessor(TreeNode root, TreeNode p) { T...
2017-09-18 12:47:00 74
转载 21. Merge Two Sorted Lists
思路:比较两个List从头的大小,小的放在前面,大的放在后面 class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode dummy = ne...
2017-09-18 11:21:00 56
转载 145. Post Order Traversal
这道题postorder相当于是反过来的preorder preorder:root left right postorder: left right root -(reverse)-> root right left class Solution { public Lis...
2017-09-18 11:04:00 318
转载 56. Merge Intervals
class Solution { public List<Interval> merge(List<Interval> intervals) { if(intervals.size() <= 1){ ...
2017-09-18 08:12:00 50
转载 88. Merge Sorted Array
class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { if(nums1 == null || nums2 == null){ return; ...
2017-09-18 08:09:00 48
转载 66. Plus One
class Solution { public int[] plusOne(int[] digits) { if(digits == null || digits.length == 0){ return digits; } ...
2017-09-17 11:44:00 66
转载 19. Remove Nth Node From End of List
有两种做法,一种是先便利获得size,然后再remove 另一种做法通过快慢指针,之间相差n的gap,之后再进行remove // normal way to solve class Solution { public ListNode removeNthFromEnd(ListN...
2017-09-17 10:56:00 48
转载 49. Group Anagrams
这道题的思路 ["eat", "tea", "tan", "ate", "nat", "bat"] 每一个单独的单词可以组成一个char数组,如果是同形异构通过排序后形成的string都是一样的,如果一样的就可以把它放进一个array中 class Solution { publ...
2017-09-17 04:24:00 42
转载 11. Container With Most Water
class Solution { public int maxArea(int[] height) { int max = 0; int left = 0; int right = height.length - 1; ...
2017-09-17 01:10:00 47
转载 155. MinStack
class MinStack { Deque <Integer> min; Deque <Integer> norm; /** initialize your data structure here. */ publi...
2017-09-17 00:15:00 52
转载 Rotated Image
class Solution { public void rotate(int[][] matrix) { if(matrix == null || matrix.length == 0 || matrix[0].length == 0){ re...
2017-09-17 00:03:00 160
转载 189. Rotated Array
一开始要进行取余操作 class Solution { public void rotate(int[] nums, int k) { if (nums.length == 0 || nums == null){ return; ...
2017-09-16 22:37:00 57
转载 438. Find All Anagrams in a String
class Solution { public List<Integer> findAnagrams(String s, String p) { List<Integer> res = new ArrayList<>...
2017-09-16 22:16:00 43
转载 143. Reorder List
1. 找到mid 2. 对mid之后的部分进行reverse 3. 重新reorder class Solution { public void reorderList(ListNode head) { if(head == null || he...
2017-09-13 09:13:00 43
转载 75. Sort Colors
这道题要注意循环条件 class Solution { public void sortColors(int[] nums) { if (nums.length == 0 || nums == null){ return; }...
2017-09-13 07:24:00 44
转载 Reverse Linked List II
因为reverse不是从头开始,而是m-n的范围,所以需要获得pre和m两个起始点和一个循环内的current,每次循环reverse一个节点直到完全reverse完毕 public class Solution { public ListNode reverseBetween(Li...
2017-09-13 06:18:00 43
转载 20. Valid Parentheses
class Solution { public boolean isValid(String s) { if (s.length() == 0 || s == null) { return false; } ...
2017-09-13 06:11:00 56
转载 56. Merge Interval
解题思路 首先对当前的intervals进行排序,用Collections.sort(intervals, (o1,o2)->Integer.compare()) 记录上一个的头尾 和上一个进行比较 class Solution { public List<Int...
2017-09-13 04:18:00 50
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人