飞柳浣纱
飞柳浣纱
全部文章
题解
归档
标签
去牛客网
登录
/
注册
飞柳浣纱的博客
全部文章
/ 题解
(共8篇)
题解 | #二叉树中和为某一值的路径#
二叉树中的回溯 上来就回溯,别问为什么,综合评分也还凑合,贴一下吧 运行时间:16ms超过80.33% 用Java提交的代码占用内存:9736KB超过73.69%用Java提交的代码 public ArrayList<ArrayList<Integer>> FindPath(...
2021-07-26
0
287
题解 | #二叉搜索树的第k个结点#
中序遍历解决树中top K问题 本题就直接用递归来做了 public class Solution { //为什么可以直接获取list中的第k-1个节点,就是所需节点? //题目已经告诉这是一棵二叉搜索树,所以是有序的(根节点的值大于左子树,小于右子树) //在中序遍历中二叉搜索树的遍历结果是从小到...
2021-07-23
0
258
题解 | #把二叉树打印成多行#
二叉树的层序打印 ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) { ArrayList<ArrayList<Integer>> result = new ArrayList<...
2021-07-23
0
275
题解 | #树的子结构#
树的子结构 递归解决 public class Solution { public boolean HasSubtree(TreeNode root1,TreeNode root2) { //这个主要是用来定位大树中节点位置的,便于与子树的头节点对应...
2021-07-22
0
309
题解 | #剪绳子#
动态规划解决剪绳子问题 有思路和解释 ``` public int cuttingRope(int n){ if (n<4) return n-1;//小于4的直接返回n-1 int[] dp = new int[n+1]; //初始化 dp[1] = 0; ...
2021-07-21
0
417
题解 | #把字符串转换成整数#
比较简单的字符串转换 if(str == null) return 0; if (str.charAt(0) >= 'a' && str.charAt(0) <= 'Z' ) return 0; boolean isNega...
2021-07-20
0
316
题解 | #最小的K个数#
top K 问题 大顶堆AC了,没什么难度 ArrayList<Integer> res = new ArrayList<>(); if (input.length == 0) return res; input = creat...
top
2021-07-20
0
291
题解 | #字符串的排列#
回溯法求排列组合问题 这题说了是存在重复字符的,要处理一下 public ArrayList<String> permutation(String str) { ArrayList<String> res = new ArrayList<>(); ...
2021-07-20
0
347