
leetcode
jing_nnn
这个作者很懒,什么都没留下…
展开
-
回溯算法求全排列
1. 回溯算法思想一、回溯算法主要思想回溯法有“通用的解题法”之称。用它可以系统地搜索一个问题的所有解或任一解。回溯法是一个既带有系统性又带有跳跃性的搜索算法,它在问题的解空间树中,按深度优先策略,从根节点出发搜索解空间树。算法搜索至解空间树的任一结点时,先判断该结点是否包含问题的解。如果不包含,则跳过对以该结点为根的子树的搜索,逐层向其祖先结点回溯。否则进入该子树,继续按深度优先策略搜索。回溯算法求问题的所有解时,要回溯到根,且根结点的所有子树都已被搜索遍才结束。回溯法求问题的一个解时,只要搜索到问题原创 2020-07-31 21:13:52 · 1622 阅读 · 0 评论 -
剑指总结--递归和循环
1. 斐波那契数列题目描述:大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。假设n<=39。解题思路:斐波那契数列:0,1,1,2,3,5,8… 总结起来就是:第一项是0,第二项是1,后续第n项为第n-1项和第n-2项之和。用公式描述如下: 看到这个公式,非常自然的可以想到直接用递归解决。但是这里存在一个效率问题,以求f(10)为例,需要先求出前两项f(9)和f(8),同样求f(9)的时候又需要求一次f(8),这样会导致很多重复计算,原创 2020-07-23 16:51:47 · 128 阅读 · 0 评论 -
动态规划
1. 动态规化解题的一般思路(标准官方):https://blog.youkuaiyun.com/ailaojie/article/details/83014821将原问题分解为子问题(开头已经介绍了怎么分解) (注意:1,子问题与原问题形式相同或类似,只是问题规模变小了,从而变简单了; 2,子问题一旦求出就要保存下来,保证每个子问题只求解一遍)确定状态(状态:在动规解题中,我们将和子问题相关的各个变量的一组取值,称之为一个"状态",一个状态对应一个或多个子问题所谓的在某个状态的值,这个就是状态所对应的子问题的原创 2020-07-05 14:59:10 · 152 阅读 · 0 评论 -
leetcode刷题--翻转二叉树
题目描述:Invert a binary tree.Example:Input: 4 / \ 2 7 / \ / \1 3 6 9Output: 4 / \ 7 2 / \ / \9 6 3 1算法思想:对于二叉树的算法基本都往递归方向考虑,那么这道题的根本是翻转左右子树交换左右子树class Solution { public TreeNode invertTree(TreeN原创 2020-06-30 20:40:41 · 172 阅读 · 0 评论 -
剑指总结---数组
1. 连续子数组的最大和动态规划思想:确定初始状态和转移状态公式即可在比较过程中,记录最大值和当前和,状态转移:当前和加上当前位是否大于当前位,若大于,就继续向后遍历,若小于,就舍弃最前一位,继续比较public class Solution { public int FindGreatestSumOfSubArray(int[] array) { int len = array.length; int max = array[0]; int原创 2020-06-28 22:43:52 · 270 阅读 · 0 评论 -
剑指总结--栈与队列
1. 用两个栈实现队列题目描述用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。class Solution{public: void push(int node) { stack1.push(node); } int pop() { int a; if(stack2.empty()){ while(!stack1.empty()){ a原创 2020-06-28 17:13:48 · 114 阅读 · 0 评论 -
leetcode刷题--Last Stone Weight
1. 题目描述We have a collection of stones, each stone has a positive integer weight.Each turn, we choose the two heaviest stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:If x == y, both s原创 2020-05-22 19:44:34 · 157 阅读 · 0 评论 -
leetcode刷题--Middle of the Linked List
1. 题目描述Given a non-empty, singly linked list with head node head, return a middle node of linked list.If there are two middle nodes, return the second middle node.2. 示例Input: [1,2,3,4,5]Output: Node 3 from this list (Serialization: [3,4,5])The return原创 2020-05-22 19:31:38 · 180 阅读 · 0 评论 -
leetcode刷题---Backspace String Compare
1. 题目描述Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.Note that after backspacing an empty text, the text will continue empty.2. 示例Input: S = "ab#c", T = "ad#c"Output: tru原创 2020-05-21 21:41:03 · 187 阅读 · 0 评论 -
字节跳动面试--算法题
字节跳动面试题:快速排序反转单链表求最长不重复字串的长度判断一个字符串是否是合法的IP地址昨天晚上的leetcde今晚两道leetcode原创 2020-05-18 16:10:27 · 817 阅读 · 0 评论 -
leetcode刷题--single number
1. 题目描述Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?2. 算法思想每个数字都会出现两次,采用位运算中的异或0 ^原创 2020-05-10 21:33:37 · 122 阅读 · 0 评论