随笔分类 - Leetcode
摘要:继续刷题 常用的函数 s.substring(start,end) 是区间[start,end) 不是区间 [start,end] 区别是end 取没有 Queue 创建 Queue queue = new LinkedList(); Leetcode 5 Boolean[][] board = n
阅读全文
摘要:很久没刷题了,现在刷一刷题找一找手感 刷题中常用到的函数 Arrays.sort(num) 排序数组 假如需要按照自己定义的排序的话 Arrary.sort(num,比较器) map.containsKey(key) map中是否有key Map.Entry<Integer, Integer> en
阅读全文
摘要:计算 3**15421过程如下: 3**15421=(3**1542)**10+3**1 // 3**1542=(3**154)**10+3**2 // 3**154= (3**15)**10+3*4 3**15=(3**1)**10+3**5这样通过有限的操作次数就能完成计算 不需要计算一万多次
阅读全文
摘要:想法:当 n为奇数时 n = (n-1)*n 当n 为偶数时 n= (n/2)(n/2)ge 编写代码如下 public double myPow(double x, int n) { if(n<0){ x= 1/x; }else { x=x; } return help(x,n); } doubl
阅读全文
摘要:if (ransomNote.length() > magazine.length()) { return false; } int[] cnt = new int[26]; for (char c : magazine.toCharArray()) { cnt[c - 'a']++; } for
阅读全文
摘要:分情况进行讨论: cnt是负数个数 1. k<=cnt 按照负数大小依次取反 2.k>cnt 存在0值或剩余取反数为偶数 不存在0值,剩余取反数为奇数: 将绝对值最小的一个取反 匿名表达式 重写Comparetor new PriorityQueue<>((a,b)->{nums[a]-nums[b
阅读全文
摘要:9比他大的只有10 排第二 3比他大的有 10 8 9 4 暴力解法 遍历一遍 Map<Integer,String>map = new HashMap<Integer,String>(); for(int i =0;i<score.length;i++ ){ //排第一位的 int biggerN
阅读全文
摘要:public int maxPower(String s) { int maxLen=0; if(s==null){ return 0; } if(s.length()==1){ return 1; } int cnt=1; for(int i=1;i<s.length();i++){ if(s.c
阅读全文
摘要:1 位数有 1*9 2 位数有 2*90 3 位数有 3 *90 n位数有 (n-1)*9* 10**n-1 确定位数: 确定数字: 确定数字的哪一位: 比如第13位 计算 13-9=4 ,从9开始偏移4个,但是偏移算的话需要从0,即有 3/2=1 10+1=11 确定是11, 3%2=1 确定下标
阅读全文

浙公网安备 33010602011771号