摘要: 如果你碰到排列组合的题,就想想是否可以用backtracking做,然后把模版记住: private List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>> subsets(int[] nums) { backt 阅读全文
posted @ 2022-02-04 12:37 阳光明媚的菲越 阅读(27) 评论(0) 推荐(0) 编辑
摘要: Solution 1: Union-Found private int[] root; private int count; public boolean validTree(int n, int[][] edges) { count = n; if(edges.length!=n-1) retur 阅读全文
posted @ 2022-02-04 11:55 阳光明媚的菲越 阅读(24) 评论(0) 推荐(0) 编辑
摘要: I have originally write a BFS solution for this problem, but it seems too difficlut. And then I read other's code, found that solution is much easier. 阅读全文
posted @ 2022-02-04 10:15 阳光明媚的菲越 阅读(16) 评论(0) 推荐(0) 编辑
摘要: Take the following nums as an exmpel : [2,4,3,1] The 4, 3, 1 is a decending order, it cannot be larger any more. How we can make 2,4,3,1 larger? we ne 阅读全文
posted @ 2022-02-04 05:56 阳光明媚的菲越 阅读(30) 评论(0) 推荐(0) 编辑
摘要: This problem is very easy to solve if using bruteforece solution, the time complexity is O(n). public double myPow(double x, int n) { if (n == 0) retu 阅读全文
posted @ 2022-02-04 04:33 阳光明媚的菲越 阅读(25) 评论(0) 推荐(0) 编辑
摘要: This is two points problem, just concentrate and carefully deal with the characters, then the problem can be solved. This is a very good problem for w 阅读全文
posted @ 2022-02-04 03:07 阳光明媚的菲越 阅读(28) 评论(0) 推荐(0) 编辑
摘要: This is the same problem with https://www.cnblogs.com/feiflytech/p/15862380.html public int[][] generateMatrix(int n) { int[][] matrix = new int[n][n] 阅读全文
posted @ 2022-02-04 02:34 阳光明媚的菲越 阅读(22) 评论(0) 推荐(0) 编辑
摘要: This is an exactly same problem with "59. Spiral Matrix II". I set every direction as a status, when one direction was implemented, the current status 阅读全文
posted @ 2022-02-04 02:32 阳光明媚的菲越 阅读(29) 评论(0) 推荐(0) 编辑