- 博客(8)
- 收藏
- 关注
原创 LeetCode538-20.9.21-二叉搜索树转换为累加树
题目链接: LeetCode538 思路:dfs反中序遍历树 看题解收获:morris减少空间复杂度 代码: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { priva
2020-09-21 20:18:39 100
原创 LeetCode77-20.9.8-组合
链接:LeetCode77 过程:怎么感觉脑子如此生涩,回忆起组合的知识,习惯性看题解。理解简单,开始的时候想难。。。 思路:枚举状态 代码: class Solution { List<List<Integer>> ans=new ArrayList<>(); List<Integer> temp=new ArrayList<>(); int n,k; public List<List<Integer&
2020-09-08 18:58:47 119
原创 LeetCode107-20.9.7-二叉树的层次遍历
链接:LeetCode107 过程:略 思路:遍历树 代码: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public List<List<Intege
2020-09-07 00:19:08 137 1
原创 LeetCode60-20.9.5-第k个排列
链接:LeetCode60 过程:意识到暴力不可取,想直接算第k个,看了看题解。 思路:问题转化,缩小求解规模,抛弃无用计算 代码: class Solution { public String getPermutation(int n, int k) { int[] factorial=new int[n]; factorial[0]=1; for(int i=1;i<n;i++)factorial[i]=factorial[i-1]*i;
2020-09-05 23:29:53 85
原创 LeetCode257-20.9.4-二叉树的所有路径
链接:LeetCode257 过程:我一眼就看出(你不是人 )是树的遍历。 思路:树的遍历,dfs或者bfs 代码: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { L
2020-09-04 20:01:11 104
原创 LeetCode51-20.9.3-N皇后
链接:LeetCode51 过程:略 思路:枚举回溯 代码: class Solution { List<List<String>> ans=new ArrayList<>(); List<String> temp=new ArrayList<>(); boolean[][] fail=null; int n; public List<List<String>> solveNQueen
2020-09-03 20:28:50 110
原创 剑指Offer30-20.9.2-表示数值的字符串
链接:题目 思路与算法:有限状态自动机 题解代码: class Solution { public boolean isNumber(String s) { Map<State, Map<CharType, State>> transfer = new HashMap<State, Map<CharType, State>>(); Map<CharType, State> initialMap = new H
2020-09-02 20:36:49 99
原创 LeetCode486-20.9.1-预测赢家
链接:LeetCode486 过程:cv 思路:递归,dp 代码: class Solution { public boolean PredictTheWinner(int[] nums) { int length = nums.length; int[][] dp = new int[length][length]; for (int i = 0; i < length; i++) { dp[i][i] = nums[i
2020-09-01 21:55:32 87
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人