LeetCode刷题
土豆洋芋山药蛋
理性的生存,诗意的栖居。
展开
-
每天刷LeetCode——D1【简单题】
题目编号:0020:validParentheseshttps://leetcode.com/problems/valid-parentheses/description题目描述:Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input stri...原创 2019-07-23 22:32:03 · 265 阅读 · 0 评论 -
动态规划从入门到放弃【1】
动态规划分治法分治法是将问题划分为互不相交的子问题,递归的求解子问题,再将它们的解组合起来,求出原问题的解。动态规划动态规划是应用于子问题重叠的情况,即不同的子问题具有公共的子子问题。最简单的动态规划问题是斐波那契数列问题,它既是递归中的典型例子也是动态规划的典型例子,在斐波那契之后将介绍典型的01背包问题,从而进一步理解动态规划。一、斐波那契数列斐波那契数列的递归求解方法:#递归...原创 2019-09-15 09:11:49 · 560 阅读 · 0 评论 -
LeetCode-字符串反转——D13【简单】
题目描述编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 char[] 的形式给出。不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。你可以假设数组中的所有字符都是 ASCII 码表中的可打印字符。示例 1:输入:[“h”,“e”,“l”,“l”,“o”]输出:[“o”,“l”,“l”,“e”,“h”]示例 2:输入:...原创 2019-08-12 23:16:19 · 248 阅读 · 0 评论 -
LeetCode-子串匹配——D12【一般难度】
题目描述实现 strStr() 函数。给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始)。如果不存在,则返回 -1。示例 1:输入: haystack = “hello”, needle = “ll”输出: 2示例 2:输入: haystack = “aaaaa”, needle =...原创 2019-08-11 23:36:23 · 295 阅读 · 0 评论 -
LeetCode-最长回文序列——D15【一般难度】
题目描述Given a string s, find the longest palindromic subsequence’s length in s. You may assume that the maximum length of s is 1000.Example 1:Input:“bbbab”Output:4One possible longest palindromic...原创 2019-08-14 21:16:38 · 286 阅读 · 0 评论 -
LeetCode-回文的判断——D14【简单】
题目描述Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome.Ex...原创 2019-08-13 23:46:15 · 280 阅读 · 0 评论 -
【LeetCode小结】二叉树遍历
二叉树作为一个基础的数据结构,遍历算法作为一个基础的算法,两者结合当然是经典的组合了。二叉数的遍历主要有前中后遍历和层次遍历。 前中后属于 DFS,层次遍历属于 BFS。 DFS 和 BFS 都有着自己的应用下面主要讨论各种遍历的迭代实现方式前序遍历这个是遍历是比较简单的,遍历的顺序为根-左-右,可以把这种遍历方式为一个“一人吃饱全家不饿”的人。拿到一个这个人(根节点),他首先想的是我要...原创 2019-08-02 01:00:14 · 286 阅读 · 1 评论 -
LeetCode-二叉树后序遍历——D10【困难】
题目描述Given a binary tree, return the postorder traversal of its nodes’ values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solution is trivi...原创 2019-08-02 00:23:03 · 246 阅读 · 0 评论 -
LeetCode-最长没有重复元素的子串——D5【一般难度】
题目描述3.longestSubstringWithoutRepeatingCharactershttps://leetcode.com/problems/longest-substring-without-repeating-characters/description/Given a string, find the length of the longest substring wit...原创 2019-07-27 23:16:32 · 207 阅读 · 0 评论 -
LeetCode-二叉树中序遍历——D9【一般难度】
题目描述Given a binary tree, return the inorder traversal of its nodes’ values.Example:Input: [1,null,2,3]12/3Output: [1,3,2]Follow up: Recursive solution is trivial, could you do it iteratively...原创 2019-07-31 23:08:29 · 230 阅读 · 0 评论 -
LeetCode-两数之和——D4【一般难度】
题目描述0002.addTwoNumbershttps://leetcode.com/problems/add-two-numbers/description/You are given two non-empty linked lists representing two non-negative integers.The digits are stored in reverse ord...原创 2019-07-26 21:49:30 · 201 阅读 · 0 评论 -
每天刷LeetCode——D3【简单题】
题目描述88.merge-sorted-array.mdhttps://leetcode.com/problems/merge-sorted-array/description/Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The numbe...原创 2019-07-25 23:29:05 · 230 阅读 · 0 评论 -
LeetCode-二叉树前序遍历——D8【一般难度】
题目描述Given a binary tree, return the preorder traversal of its nodes’ values.Example:Input: [1,null,2,3]12/3Output: [1,2,3]Follow up: Recursive solution is trivial, could you do it iterativel...原创 2019-07-30 22:20:40 · 415 阅读 · 0 评论 -
LeetCode-二叉树层次遍历——D11【一般难度】
题目描述Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20...原创 2019-08-02 23:58:50 · 249 阅读 · 0 评论 -
每天刷LeetCode——D2【简单题】
题目编号:0026.remove-duplicates-from-sorted-array题目描述:Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra ...原创 2019-07-25 00:25:00 · 286 阅读 · 0 评论 -
LeetCode-3数之和为0——D7【一般难度】
题目描述Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not c...原创 2019-07-29 23:38:10 · 212 阅读 · 0 评论 -
LeetCode-最长回文串——D6【一般难度】
题目描述5.longest-palindromic-substringhttps://leetcode.com/problems/longest-palindromic-substring/description/Given a string s, find the longest palindromic substring in s. You may assume that the max...原创 2019-07-29 00:13:01 · 231 阅读 · 0 评论 -
动态规划从入门到放弃【2】
动态规划从入门到放弃【2】本文将利用“最大子序列和”问题来对比动态规划和其它算法之间的在实现上的区别。最大子序列和问题给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。示例:输入: [-2,1,-3,4,-1,2,1,-5,4],输出: 6解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。进阶:如果你已经实现复杂度为...原创 2019-09-16 23:10:29 · 799 阅读 · 0 评论