![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
基础算法
文章平均质量分 52
Freeman_zxp
这个作者很懒,什么都没留下…
展开
-
【LeetCode】295.寻找数据流中的中位数
295. Find Median from Data StreamDescription:Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two m...原创 2019-04-15 15:47:22 · 505 阅读 · 0 评论 -
【LeetCode】572. Subtree of Another Tree
572. Subtree of Another TreeDescription:Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree co...原创 2019-01-22 13:34:14 · 152 阅读 · 0 评论 -
【LeetCode】114. Flatten Binary Tree to Linked List
114. Flatten Binary Tree to Linked ListDescription:Given a binary tree, flatten it to a linked list in-place.Difficulty:MediumExample: 1 / \ 2 5 / \ \3 4 61 \ 2 \ 3...原创 2019-01-27 17:16:23 · 190 阅读 · 0 评论 -
【LeetCode】309. Best Time to Buy and Sell Stock with Cooldown
309. Best Time to Buy and Sell Stock with CooldownDescription: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....原创 2019-01-27 16:31:24 · 184 阅读 · 0 评论 -
【LeetCode】394. Decode String
394. Decode StringDescription:The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a posit...原创 2019-01-27 14:21:55 · 157 阅读 · 0 评论 -
【LeetCode】96. Unique Binary Search Trees
96. Unique Binary Search TreesDescription:Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?Difficulty:MediumExample:Input: 3Output: 5Explanation:Given...原创 2019-01-27 13:27:33 · 137 阅读 · 0 评论 -
【LeetCode】236. Lowest Common Ancestor of a Binary
236. Lowest Common Ancestor of a Binary Description:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The ...原创 2019-01-31 17:58:36 · 182 阅读 · 0 评论 -
【LeetCode】416. Partition Equal Subset Sum
416. Partition Equal Subset SumDescription:Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both sub...原创 2019-01-26 21:15:13 · 195 阅读 · 0 评论 -
【LeetCode】438. Find All Anagrams in a String
438. Find All Anagrams in a StringDescription:Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.Strings consists of lowercase English letters only and the l...原创 2019-01-16 13:44:54 · 117 阅读 · 0 评论 -
【LeetCode】101. Symmetric Tree
101. Symmetric TreeDescription:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).**Note:**Bonus points if you could solve it both recursively and iterati...原创 2019-01-21 21:00:41 · 109 阅读 · 0 评论 -
【LeetCode】494. Target Sum
494. Target SumDescription:You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its...原创 2019-01-26 17:56:22 · 329 阅读 · 1 评论 -
【LeetCode】136. Single Number
136. Single NumberDescription: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. Cou...原创 2019-01-16 11:03:21 · 176 阅读 · 0 评论 -
【LeetCode】215. Kth Largest Element in an Array
215. Kth Largest Element in an ArrayDescription:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Difficu...原创 2019-01-26 16:04:55 · 199 阅读 · 0 评论 -
【LeetCode】102. Binary Tree Level Order Traversal
102. Binary Tree Level Order TraversalDescription:Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).Difficulty:MediumExample:Gi...原创 2019-01-26 13:43:49 · 154 阅读 · 0 评论 -
【LeetCode】70. Climbing Stairs
70. Climbing StairsDescription:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?*...原创 2019-01-21 20:10:30 · 108 阅读 · 0 评论 -
【LeetCode】543. Diameter of Binary Tree
543. Diameter of Binary TreeDescription:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any t...原创 2019-01-21 19:39:36 · 137 阅读 · 0 评论 -
【LeetCode】42. Trapping Rain Water
42. Trapping Rain WaterDescription:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.Difficulty:...原创 2019-01-15 21:32:58 · 120 阅读 · 0 评论 -
【LeetCode】240. Search a 2D Matrix II
240. Search a 2D Matrix IIDescription:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascendi...原创 2019-01-27 18:42:24 · 162 阅读 · 0 评论 -
【LeetCode】300. Longest Increasing Subsequence
300. Longest Increasing SubsequenceDescription:Given an unsorted array of integers, find the length of longest increasing subsequence.Difficulty:MediumExample:Input: [10,9,2,5,3,7,101,18]Output:...原创 2019-01-27 19:39:14 · 222 阅读 · 0 评论 -
【LeetCode】23.K个有序链表合并
23. Merge k Sorted ListsDescription:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Difficulty:hardExample:Input:[ 1->4->5, 1->3-&...原创 2019-04-12 15:38:43 · 320 阅读 · 0 评论 -
【LeetCode】145. 二叉树后续遍历
102. Binary Tree Postorder TraversalDescription:Given a binary tree, return the postorder traversal of its nodes’ values.Difficulty:hardExample:Input: [1,null,2,3] 1 \ 2 / 3...原创 2019-04-12 13:14:33 · 353 阅读 · 0 评论 -
【LeetCode】69. Sqrt(x)
69. Sqrt(x)Description:Implement int sqrt(int x).Difficulty:EasyExample:Input: 8Output: 2Explanation: The square root of 8 is 2.82842..., and since the decimal part is truncated, ...原创 2019-01-30 21:52:26 · 178 阅读 · 0 评论 -
【LeetCode】139. Word Break
139. Word BreakDescription:Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more d...原创 2019-01-30 16:46:54 · 179 阅读 · 0 评论 -
【LeetCode】208. Implement Trie (Prefix Tree)
208. Implement Trie (Prefix Tree)Description:Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.All inputs are ...原创 2019-01-30 15:22:33 · 137 阅读 · 0 评论 -
【LeetCode】207. Course Schedule
207. Course ScheduleDescription:There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take cours...原创 2019-01-29 14:53:04 · 157 阅读 · 0 评论 -
【LeetCode】160. Intersection of Two Linked Lists
160. Intersection of Two Linked ListsDescription:Write a program to find the node at which the intersection of two singly linked lists begins.Difficulty:EasyNote:1.If the two linked lists have no...原创 2019-01-23 13:41:46 · 127 阅读 · 0 评论 -
【LeetCode】155. Min Stack
155. Min StackDescription:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element on top of...原创 2019-01-23 13:00:54 · 245 阅读 · 0 评论 -
【LeetCode】200. Number of Islands
200. Number of IslandsDescription:Given a 2d grid map of '1’s (land) and '0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizo...原创 2019-01-28 21:06:37 · 162 阅读 · 0 评论 -
【LeetCode】17. Letter Combinations of a Phone Number
17. Letter Combinations of a Phone NumberDescription:Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit ...原创 2019-01-28 16:53:26 · 155 阅读 · 0 评论 -
【LeetCode】141. Linked List Cycle
141. Linked List CycleDescription:Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexe...原创 2019-01-22 19:57:10 · 149 阅读 · 0 评论 -
【LeetCode】198. House Robber
198. House RobberDescription:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each...原创 2019-01-22 19:38:23 · 268 阅读 · 0 评论 -
【LeetCode】122. Best Time to Buy and Sell Stock II
122. Best Time to Buy and Sell Stock IIDescription: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 co...原创 2019-02-01 23:00:38 · 166 阅读 · 0 评论 -
【LeetCode】371. Sum of Two Integers
371. Sum of Two Integers Description:Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Difficulty:Easy方法:位操作class Solution {public: int getSum(i...原创 2019-02-01 21:39:04 · 144 阅读 · 0 评论 -
【LeetCode】347. Top K Frequent Elements
347. Top K Frequent ElementsDescription:Given a non-empty array of integers, return the k most frequent elements.Note:You may assume k is always valid, 1 ≤ k ≤ number of unique elements.Your algo...原创 2019-01-16 21:06:45 · 130 阅读 · 0 评论 -
【LeetCode】94. Binary Tree Inorder Traversal
94. Binary Tree Inorder TraversalDescription:Given a binary tree, return the inorder traversal of its nodes’ values.Difficulty:MediumExample:Input: [1,null,2,3] 1 \ 2 / 3Outp...原创 2019-01-16 19:26:20 · 96 阅读 · 0 评论 -
【LeetCode】33. Search in Rotated Sorted Array
33. Search in Rotated Sorted ArrayDescription:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7]might become [4,5,6,7,0,1,2]).You...原创 2019-01-15 20:21:49 · 136 阅读 · 0 评论 -
【LeetCode】337. House Robber III
337. House Robber IIIDescription:The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and...原创 2019-01-25 20:52:37 · 229 阅读 · 0 评论 -
【LeetCode】238. Product of Array Except Self
238. Product of Array Except SelfDescription:Given an array nums of n integers where n > 1, return an array output such that output[i]is equal to the product of all the elements of nums except ...原创 2019-01-12 15:45:07 · 140 阅读 · 0 评论 -
【LeetCode】581. Shortest Unsorted Continuous Subarray
581. Shortest Unsorted Continuous SubarrayDescription:Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array w...原创 2019-01-12 14:22:34 · 115 阅读 · 0 评论 -
【LeetCode】53. Maximum Subarray
53. Maximum SubarrayDescription:Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Difficulty:EasyExample:Inp...原创 2019-01-12 10:53:20 · 210 阅读 · 0 评论