文章 2018-07-29 来自:开发者社区

java -----------------LeetCode——电话号码的字母组合

回溯算法是不是很是陌生啊,我敢开始也是一脸你蒙蔽,后来我终于忍不住了,就去查查什么是回溯,原来是这个情况,回溯和递归有点类似,但是又不是递归,比如我现在计算数据从0开始到2,当到达状态值2我就回溯,我从1开始回溯,我在回到0,就是for循环我不按套路从小到打,去输出了,我采用回溯, public class Main { public static void main(String[...

文章 2018-07-29 来自:开发者社区

Java---------- LeetCode——746. 使用最小花费爬楼梯

这个是最让我郁闷的我操,我用了一上午的时间来实现它,当然了刚开始我并没有用动态规划,我用自己的方式来实现,其实我不知道要用动态规划来实现它,写了一上午,最后发现,在LeetCode测试时,有些数据通不过啊,于是乎我就打补丁,打打补丁,最后发现实在打不下去补丁了,就于是乎用动态规划实现,但是我不会动态规划啊,那怎么办,学啊,我学了一会儿,感觉够用了, public static int min...

文章 2018-07-29 来自:开发者社区

java之 ------------[LeetCode] House Robber 打家劫舍

刚开始做这一道题感觉卧槽,这不简单吗,直接去把数组下标和2取余的数相加再把剩下的数相加,比较这两个和谁大就输出谁,不就行了,但是啊,我操,事实证明,我还是太天真了,我操出现[2,1,1,2]这种情况,我当时还怀疑为什么那么简单后来一想,我操,这不是动态规划吗,于是乎,恶补一下怎么实现动态规划的,说白了,动态规划就是把大的数据拆成小的数据,如我想计算f(10),我就要计算出f(9)+1,然后我想计....

文章 2018-05-23 来自:开发者社区

leetcode算法题解(Java版)-17-图的巧妙用法

一、图 题目描述 Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()(())", "....

文章 2018-05-22 来自:开发者社区

leetcode算法题解(Java版)-16-动态规划(单词包含问题)

一、递归 题目描述 Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 思路 碰到....

文章 2018-05-21 来自:开发者社区

leetcode算法题解(Java版)-15-动态规划(斐波那契)

一、二叉树遍历 题目描述 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node ....

文章 2018-05-20 来自:开发者社区

leetcode算法题解(Java版)-14-第k小数问题

一、第k小数问题 题目描述 There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 思路 题目要求在O(log(m+n))时.....

文章 2018-05-19 来自:开发者社区

leetcode算法题解(Java版)-13-经典反转链表

一、简单二分搜索 题目描述 Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates i....

文章 2018-05-18 来自:开发者社区

leetcode算法题解(Java版)-12-中序遍历

日子又恢复正常了,浪了半个月。。。还是学习的时候感觉好~~ 一、动态规划 题目描述 Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique BST's. 1...

文章 2018-05-06 来自:开发者社区

leetcode算法题解(Java版)-11-贪心大法

一、全排列变式(递归) 题目描述 Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[2....

本页面内关键词为智能算法引擎基于机器学习所生成,如有任何问题,可在页面下方点击"联系我们"与我们沟通。

产品推荐

Java开发者

Java开发者成长课堂,课程资料学习,实战案例解析,Java工程师必备词汇等你来~

+关注