![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
【leetcode】
哈哈哈哈嘿嘿嘿
这个作者很懒,什么都没留下…
展开
-
[LeetCode]726. Number of Atoms
题意:给定一个以字符串表示的化学表达式,求表达式中每个原子及其个数。思路:递归,也可以用栈,一样的思路。原创 2017-11-28 14:28:07 · 1417 阅读 · 0 评论 -
[LeetCode]189. Rotate Array
题意:将给定的数组向右循环挪位k次。思路:1、暴力循环法2、使用额外空间存储3、链式循环法4、倒置法原创 2017-10-11 15:36:18 · 206 阅读 · 0 评论 -
[LeetCode]395. Longest Substring with At Least K Repeating Characters
题意:给定一个字符串,返回一个所有字符出现次数都不小于k的子字符串最大长度。原创 2017-10-28 10:02:11 · 215 阅读 · 0 评论 -
[LeetCode][94,144,145]Binary Tree (Pre/In/Post)order Traversal
经典问题:使用非递归方法对二叉树进行先序、中序、后序遍历。思路:都需要借助数据结构——栈(Stack)来实现。根据每个遍历的特性:先序遍历先输出根节点,然后左子树,最后右子树;中序遍历先输出左子树,然后根节点,最后右子树;后序遍历先输出左子树,然后右子树,最后根节点;我们可以得到代码设计的主要思路。原创 2017-09-20 21:07:10 · 181 阅读 · 0 评论 -
[LeetCode][105,106] Construct Binary Tree from Inorder and (Post/Pre)order Traversal
题意:通过前序遍历和中序遍历,或后序遍历和中序遍历,构造一棵二叉树。思路:递归构造。原创 2017-09-24 21:15:15 · 268 阅读 · 0 评论 -
[LeetCode]98. Validate Binary Search Tree
题意:判断给定的二叉搜索树是否合法原创 2017-09-21 10:47:26 · 190 阅读 · 0 评论 -
[LeetCode]139. Word Break
题意:判断给定string数组中是否含有能组成给定字符串s的子字符串集合。思路:动态规划。新建一个长度为s.length()+1的bool数组dp,除数组第一位用于方便通过进入循环的边界判断外,其他每一位对应字符串s的每一个字符。当dp[i]=true时,表示在字符串数组中,存在一个这样的字符串,等同于在字符串s中,从任意一个或多个下标为0,1,2,...,i-1开始,到下标为i结束的子字符串。从头开始对字符串s进行遍历,这样循环操作之后,dp[s.length()]就是所求得的判断布尔值。原创 2017-09-19 20:03:05 · 302 阅读 · 0 评论 -
[LeetCode]679. 24 Game
题意:模拟24点游戏,给定一个只有4个元素的数组,且每个元素值在1~9之间,判断是否能通过+,-,*,/得到24.思路:回溯。原创 2017-10-19 09:55:53 · 2594 阅读 · 2 评论 -
[LeetCode]295. Find Median from Data Stream
题意:在可变数组下,高效地寻找这一组数的中位数。思路:【TLE】①使用插入排序。时间复杂度:O(logn) + O(n) ~ O(n)。【TLE】②使用快速排序。时间复杂度:O(nlogn)【AC】③使用双堆排序。时间复杂度:O(5*logn)。原创 2017-09-30 16:27:37 · 253 阅读 · 0 评论 -
[LeetCode]435. Non-overlapping Intervals
思路:尽可能多的举办活动,而活动的数量取决于每个活动时间的结束时间,而不在于开始时间、持续时间。贪心算法:初始化一个空的集合S,将输入数组按结束时间增序排序,遍历数组,若当前interval的开始时间大于等于上一个interval的结束时间,则加入到集合S中,直到遍历结束,(这样得到的集合S就是互不重叠的interval),最后用初始数组大小减去集合S的大小即可。原创 2017-09-15 21:23:35 · 274 阅读 · 0 评论 -
[LeetCode]621. Task Scheduler
题意:模拟CPU的任务调度。给定一组字符数组和数值n,字符数组中每个字符表示一种任务,每个任务需要一个单位时间完成,n表示相同任务之间必须有n个单位时间间隔着。求完成所有任务需要的时间。原创 2017-09-18 14:40:55 · 502 阅读 · 0 评论 -
[LeetCode]141. Linked List Cycle
题意:给定一个链表,判断是否存在环路。思路:第一种方法:使用哈希表存储查询,但需要消耗空间。第二种方法:使用两个指针遍历链表,一个快(一次迭代移两个节点),一个慢(一次迭代移一个节点),若快指针指向了NULL,则没有循环。若两指针重合,则存在循环。原创 2017-09-13 19:49:24 · 168 阅读 · 0 评论 -
[LeetCode]310. Minimum Height Trees
题意:给定一组符合树特性的无向图,找出可以作为根的结点,使得整个树变成最小高度树。原创 2017-11-15 11:07:08 · 195 阅读 · 0 评论 -
[LeetCode]167. Two Sum II - Input array is sorted
题意:在给定一数组中找到两个元素,其值相加等于给定数值target。原创 2017-09-06 14:05:29 · 297 阅读 · 0 评论 -
[LeetCode]152. Maximum Product Subarray
题意:在给定数组中找到连续元素组成的子数组,使得它们的乘积最大。(有正数、负数、0)思路:和53. Maximum Subarray不同,这里的负数乘积之前需要“交换”局部最大和最小值,以此得到全局最大值。原创 2017-09-19 20:55:53 · 280 阅读 · 0 评论 -
[LeetCode]221. Maximal Square
题意:在给定由“0”和“1”组成的数组中找到最大的由“1”组成的正方形。思路:动态规划。原创 2017-09-20 20:53:50 · 233 阅读 · 0 评论 -
[LeetCode]46. Permutations
题意:找出给定数组的所有置换序列。思路:回溯。原创 2017-09-21 22:20:17 · 142 阅读 · 0 评论 -
[LeetCode]123. Best Time to Buy and Sell Stock III
题意:任意两天买入卖出,求获得利润的最大值。(卖出必须在买入之后,第二次买入必须在第一次买入之后)原创 2017-09-25 21:40:23 · 201 阅读 · 0 评论 -
[LeetCode]322. Coin Change
题意:凑金钱面额。思路:动态规划。这里的动态规划数组不是基于面值数量的数组,而是基于需要凑整的面额数组。原创 2017-09-26 20:14:11 · 211 阅读 · 0 评论 -
[LeetCode]36. Valid Sudoku
判断当前给定数组,是否符合“数独”规则。原创 2017-09-11 11:24:45 · 191 阅读 · 0 评论 -
[LeetCode]109. Convert Sorted List to Binary Search Tree
题意:将给定增序的单向链表转换成平衡二叉树。思路:平衡二叉树的特性是左右子树高度差不超过1,。利用这个特性,我们可以使用递归的方法,每次“对半”搜索当前链表的正中间或靠左或靠右节点,将它作为这一层的根,然后将在它之前的的链表作为它的左子树,在它之后的链表作为它的右子树,不断重复递归即可。原创 2017-09-13 14:09:13 · 201 阅读 · 0 评论 -
[LeetCode]110. Balanced Binary Tree
题意:判断一个给定二叉树是否高度平衡(左右子树高度差不超过1).思路:递归。原创 2017-09-15 12:20:50 · 222 阅读 · 0 评论 -
[LeetCode]653. Two Sum IV - Input is a BST
题意:给定给一个二叉搜索树和一个数值target,判断树中是否含有两个元素值相加等于target。思路:一开始我的思路是用广度优先搜索(BFS):原创 2017-09-06 18:41:24 · 340 阅读 · 0 评论 -
[LeetCode]55. Jump Game
Description:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that positi原创 2017-09-09 21:00:43 · 218 阅读 · 0 评论 -
[LeetCode]48. Rotate Image
Description:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify原创 2017-09-09 20:33:10 · 177 阅读 · 0 评论 -
[LeetCode]40. Combination Sum II
Description:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used o原创 2017-09-08 15:09:11 · 223 阅读 · 0 评论 -
[LeetCode]53. Maximum Subarray
Description:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous suba原创 2017-09-08 12:45:40 · 212 阅读 · 0 评论 -
[LeetCode]376. Wiggle Subsequence
Description:A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists)原创 2017-09-15 14:03:12 · 194 阅读 · 0 评论 -
[LeetCode]31. Next Permutation
Description:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as t原创 2017-09-07 15:00:20 · 197 阅读 · 0 评论 -
[LeetCode]15. 3Sum
Description:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution se原创 2017-09-07 11:14:50 · 213 阅读 · 0 评论 -
[LeetCode]11. Container With Most Water
Description:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at原创 2017-09-06 20:00:17 · 198 阅读 · 0 评论 -
[LeetCode]122. Best Time to Buy and Sell Stock II
Description:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as yo原创 2017-09-14 14:34:53 · 115 阅读 · 0 评论 -
[LeetCode]7. Reverse Integer
Description:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questio原创 2017-09-13 21:02:19 · 155 阅读 · 0 评论 -
[LeetCode]54. Spiral Matrix
Description:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ],原创 2017-09-09 21:35:05 · 176 阅读 · 0 评论 -
[LeetCode]442. Find All Duplicates in an Array
Description:Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could yo原创 2017-09-13 18:52:46 · 140 阅读 · 0 评论 -
[LeetCode]39. Combination Sum
Description:Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated num原创 2017-09-08 13:32:15 · 174 阅读 · 0 评论 -
[LeetCode]16. 3Sum Closest
Description:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input原创 2017-09-07 11:50:25 · 159 阅读 · 0 评论 -
[LeetCode]35. Search Insert Position
Description: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 duplic原创 2017-09-07 20:59:33 · 157 阅读 · 0 评论 -
[LeetCode]19. Remove Nth Node From End of List
Description:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node原创 2017-09-11 19:58:37 · 182 阅读 · 0 评论 -
[LeetCode]204. Count Primes
Description:Description:Count the number of prime numbers less than a non-negative number, n.Credits:Special thanks to @mithmatt for adding this problem and creating all test cases.—原创 2017-09-11 12:27:51 · 164 阅读 · 0 评论