摘要:
1732. 找到最高海拔 class Solution { public int largestAltitude(int[] gain) { int res = 0; int high = 0; for(int i = 0; i < gain.length; i ++) { high += gain 阅读全文
摘要:
792. 匹配子序列的单词数 // 时间复杂度 n + m * k public int numMatchingSubseq(String s, String[] words) { List<List<Pair>> list = new ArrayList<>(); for (int i = 0; 阅读全文
摘要:
775. 全局倒置与局部倒置 题解: 用归并排序求全局倒置(逆序对) 可以用树状数组求逆序对 class Solution { int num2 = 0; public boolean isIdealPermutation(int[] nums) { int n = nums.length; if 阅读全文
摘要:
1710. 卡车上的最大单元数 class Solution { public int maximumUnits(int[][] boxTypes, int truckSize) { int n = boxTypes.length; Arrays.sort(boxTypes, Comparator. 阅读全文
摘要:
791. 自定义字符串排序 class Solution { int[] w = new int[30]; public String customSortString(String order, String s) { for (int i =0 ; i < 26;i ++) { w[i] = 3 阅读全文
摘要:
34. 在排序数组中查找元素的第一个和最后一个位置 class Solution { public int[] searchRange(int[] nums, int target) { if (nums.length == 0) return new int[]{-1, -1}; // 搜左边界 阅读全文
摘要:
35. 搜索插入位置 class Solution { public int searchInsert(int[] nums, int target) { int l = 0, r = nums.length - 1; while (l < r) { int mid = l + ((r - l) > 阅读全文