
牛客剑指offer
sunlili_yt
这个作者很懒,什么都没留下…
展开
-
递归与回溯(Leecode17/46/77/79/200/51)
class Solution { private List<String> slist=new ArrayList<String>(); String numtochar[]={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; public void findString(Str...原创 2020-09-13 09:18:41 · 200 阅读 · 1 评论 -
Java——从递归到动态规划(Leecode343/198)
class Solution { public int integerBreak(int n) { if(n<2) return -1; return HelperInteger(n); } public int HelperInteger(int n){ if(n==2||n==1) return 1; ...原创 2020-09-13 09:18:54 · 246 阅读 · 0 评论 -
Java——贪心算法(Leecode455/392)
class Solution { public int findContentChildren(int[] g, int[] s) { //O(nlogn) Arrays.sort(g);//孩子 Arrays.sort(s);//饼干 int count = 0; int i = s.length-1; ...原创 2020-09-13 09:19:05 · 164 阅读 · 0 评论 -
牛客剑指offer——跳台阶/变态跳台阶
一、跳台阶问题描述:一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果)。解法一:构造二叉树(回溯)将该问题的解法构造为一棵树,左子树遍历+1,右子树遍历+2;当结点的台阶总数==target,则计数器+1;若节点当前走过的setp总和已经超过target那么返回上一层,不计数。缺点:复杂度高,没有进行剪枝的优化publ...原创 2020-04-17 11:51:03 · 180 阅读 · 0 评论