摘要:
分别计算左右边界 o(N) o(N) class Solution { public int trap(int[] height) { /* 分别考虑每一个高度为底的情况,当前高度所能盛水量等于左侧边界和右侧边界高度中最小值减去当前元素高度 */ int size = height.length; 阅读全文
摘要:
1.暴力解法 O(n^2) class Solution { public int canCompleteCircuit(int[] gas, int[] cost) { int length = gas.length; //把当前i节点作为起始节点 for(int i = 0; i < lengt 阅读全文
摘要:
就用除法 class Solution { public int[] productExceptSelf(int[] nums) { int[] answer = new int[nums.length]; int sum = 1; int zeroNum = 0; for (int i = 0; 阅读全文
摘要:
先来个大的 class RandomizedSet { private HashSet<Integer> hashSet; public RandomizedSet() { hashSet = new HashSet<Integer>(); } public boolean insert(int v 阅读全文
摘要:
class Solution { public int jump(int[] nums) { if (nums.length <= 1) return 0; //记录每次起跳所能跳到的最远的距离 int farestIndex = 0; int maxIndex = 0; int start = 0 阅读全文