public class ReConstructBinaryTree { public static TreeNode reConstructBinaryTree(int[] pre, int[] in) { //参数检查 if (pre...
class Solution { public int numWays(int n) { if(n < 2){ return 1; } if(n == 2){ return n; } int a = 1, b = 2, sum = 2;...
class Solution { public int minArray(int[] numbers) { int low = 0; int high = numbers.length - 1; while (low < high) {...
/** * 不保序 */ public class ReOrderArray { public void reOrderArray2(int[] array) { if (array == null || array.length ==...
class Solution { public ListNode getKthFromEnd(ListNode head, int k) { if (head == null || k <= 0) { return null; }...
class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null; ListNode curr = head; while (curr !=...
public class Merge { public ListNode Merge(ListNode list1, ListNode list2) { if(list1 == null && list2 == null){ return...
public class HasSubtree { public boolean HasSubtree(TreeNode root1, TreeNode root2) { if (root1 == null || root2 ==...
class Solution { public int[] spiralOrder(int[][] matrix) { ArrayList<Integer> list = new ArrayList<Integer>(); if...
哈希表统计法: 遍历数组 nums ,用 HashMap 统计各数字的数量,即可找出 众数 。此方法时间和空间复杂度均为 O(N) 。 数组排序法: 将数组 nums 排序,数组中点的元素 一定为众数。 摩尔投票法: 核心理念为 票数正负...