
LeetCode
garett.
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
「LeetCode639」简单DP
class Solution { public static final long MOD=1000000007; public int numDecodings(String str) { char[] s=str.toCharArray(); int n=s.length; long[] dp=new long[n]; if(s[0]=='0') return 0; dp[0]=(.原创 2021-09-27 10:15:41 · 101 阅读 · 0 评论 -
[LeetCode] 第167场周赛题解
第一次进第一页QAQ,然而还是手慢,在第二题浪费了好久的时间。 第一题: public class Solution { public int getDecimalValue(ListNode head) { int ans=0; ListNode temp=head; while(temp!=null) { an...原创 2019-12-15 15:16:34 · 203 阅读 · 2 评论 -
[LeetCode] 第166场周赛题解
第一题: 按题意模拟。 public class Solution { public int subtractProductAndSum(int n) { String s=Integer.toString(n); int a=1; int b=0; for(int i=0;i<s.length();i++) { ...原创 2019-12-10 08:22:31 · 160 阅读 · 0 评论 -
[LeetCode] 第165场周赛题解
第一题: 按题意模拟。 public class Solution { public boolean check(int[][] map,int val) { for(int i=0;i<3;i++) { if(map[i][0]==val&&map[i][1]==val&&map[i][2]==val) return true; ...原创 2019-12-10 08:17:49 · 159 阅读 · 0 评论 -
[LeetCode] 第159场周赛题解
第一题: 为防止丢失精度用乘法代替除法。 public class Solution { public boolean checkStraightLine(int[][] c) { boolean flag=true; for(int i=2;i<c.length;i++) { if((c[i][1]-c[i-1][...原创 2019-11-27 15:42:17 · 184 阅读 · 0 评论 -
[LeetCode] 第160场周赛题解
第一题: 因为该函数具有严格的单调性,所以可以二分,即枚举x二分y,但数据范围过小没啥必要。 public class Solution { public List<List<Integer>> findSolution(CustomFunction func, int z) { List<List<Integer>> ans=new A...原创 2019-11-27 10:51:39 · 363 阅读 · 0 评论 -
[LeetCode] 第161场周赛题解
第一题: 根据每列的字符分组,xx和yy跳过,剩下xy和yx,其中两个相同的xy或yx都只需一次就可转换成相同的,最后两两配对,若这两组最后都只剩下一个没有完成配对,则这两个剩下的配对,需要交换两次,若一组完全配对,另一组剩一个,则无解。 public class Solution { public int minimumSwap(String s1, String s2) { ...原创 2019-11-26 19:37:11 · 253 阅读 · 0 评论 -
[LeetCode]第162场周赛题解
第一题: 分别维护每行每列添加的总和,最后加起来统计即可。 class Solution { public int oddCells(int n, int m, int[][] indices) { int ans=0; int[] r=new int[n]; int[] c=new int[m]; f...原创 2019-11-26 17:43:55 · 269 阅读 · 0 评论 -
[LeetCode]第163场周赛题解
第一题: 首先让k%(n*m),再把二维数组转换成一维,后面比较容易处理。 public class Solution { public List<List<Integer>> shiftGrid(int[][] g, int k) { int n=g.length; int m=g[0].length; List<List<Inte...原创 2019-11-26 15:58:23 · 223 阅读 · 0 评论 -
[LeetCode]第164场周赛题解
第一题 没啥好说的,签到题。 public class Solution { public int minTimeToVisitAllPoints(int[][] p) { int ans=0; for(int i=1;i<p.length;i++) { ans+=Math.max(Math.abs(p[i][...原创 2019-11-25 11:06:43 · 144 阅读 · 1 评论