Algorithm Problem
LingzeHu2020
这个作者很懒,什么都没留下…
展开
-
1360. Symmetric Tree
1360. Symmetric TreeDescription:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).ExampleExample1Input: {1,2,2,3,4,4,3}Output: trueExplanation:1/ ...原创 2020-02-02 05:03:49 · 126 阅读 · 0 评论 -
189. First Missing Positive
[Problem Name](probelm link/description)Description:Given an unsorted integer array, find the first missing positive integer.ExampleExample 1:Input:[1,2,0]Output:3Example 2:Input:[3,4,-1,1]Ou...原创 2020-02-01 02:18:28 · 158 阅读 · 0 评论 -
50. Product of Array Exclude Itself
50. Product of Array Exclude ItselfDescription:Given an integers array A.Define B[i] = A[0] * … * A[i-1] * A[i+1] * … * A[n-1], calculate B WITHOUT divide operation.Out put BExampleExample 1Inpu...原创 2020-02-01 02:09:34 · 119 阅读 · 0 评论 -
56. Two Sum
56. Two SumDescription:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add...原创 2020-02-01 01:56:09 · 124 阅读 · 0 评论 -
64. Merge Sorted Array
64. Merge Sorted ArrayDescription:Given two sorted integer arrays A and B, merge B into A as one sorted array.ExampleExample 1:Input:[1, 2, 3] 3 [4,5] 2Output:[1,2,3,4,5]Explanation:After me...原创 2020-01-31 05:58:44 · 131 阅读 · 0 评论 -
100. Remove Duplicates from Sorted Array
100. Remove Duplicates from Sorted ArrayDescription:Given a sorted array, ‘remove’ the duplicates in place such that each element appear only once and return the ‘new’ length.Do not allocate extra ...原创 2020-01-31 05:46:57 · 104 阅读 · 0 评论 -
138. Subarray Sum
138. Subarray SumDescription:Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the last number.Example...原创 2020-01-31 05:41:58 · 172 阅读 · 0 评论 -
172. Remove Element
172. Remove ElementDescription:Given an array and a value, remove all occurrences of that value in place and return the new length.The order of elements can be changed, and the elements after the n...原创 2020-01-30 07:41:15 · 148 阅读 · 0 评论 -
78. Longest Common Prefix
78. Longest Common PrefixDescription:Given k strings, find the longest common prefix (LCP).ExampleExample 1:Input: “ABCD”, “ABEF”, “ACEF”Output: “A”Example 2:Input: “ABCDEFG”, “ABCEFG” and “...原创 2020-01-30 07:34:51 · 133 阅读 · 1 评论 -
79. Longest Common Substring
79. Longest Common SubstringDescription:Given two strings, find the longest common substring.Return the length of it.ExampleExample 1:Input: “ABCD” and “CBCE”Output: 2Explanation:Longest co...原创 2020-01-30 07:28:31 · 177 阅读 · 0 评论 -
13. Implement strStr()
13. Implement strStr()Tag:StringDescription:For a given source string and a target string, you should output the first index(from 0) of target string in source string.If target does not exist in ...原创 2020-01-25 15:53:46 · 128 阅读 · 0 评论 -
55. Compare Strings / 158. Valid Anagram
55. Compare Strings / 158. Valid AnagramTag:Hash Table, MapDescription:55. Compare StringsCompare two strings A and B, determine whether A contains all of the characters in B.The characters in s...原创 2020-01-25 15:37:17 · 1438 阅读 · 1 评论 -
452. Remove Linked List Elements
452. Remove Linked List ElementsDescription:Remove all elements from a linked list of integers that have value val.ExampleExample 1:Input: head = 1->2->3->3->4->5->3->null, v...原创 2020-01-24 05:03:51 · 134 阅读 · 0 评论 -
4.Study Note of Object Oriented Programming (OOP):Operator Overloading
Operator OverloadingOverview:This chapter discuss about the operator overloading in C++. It is common used component in C++ programming. Personally speaking, the most used operator overloading is th...原创 2020-01-24 02:00:15 · 201 阅读 · 0 评论 -
167. Add Two Numbers
167. Add Two NumbersDescription:You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the ...原创 2020-01-22 05:40:44 · 195 阅读 · 0 评论 -
223. Palindrome Linked List
35. Reverse Linked ListDescription:Implement a function to check if a linked list is a palindrome.ExampleExample 1:Input: 1->2->1output: trueExample 2:Input: 2->2->1output: false...原创 2020-01-21 14:11:31 · 162 阅读 · 0 评论 -
104. Merge K Sorted Lists
104. Merge K Sorted ListsDescription:Merge k sorted linked lists and return it as one sorted list.Analyze and describe its complexity.ExampleExample 1:Input: [2->4->null,null,-1->null...原创 2020-01-21 08:57:40 · 210 阅读 · 0 评论 -
165. Merge Two Sorted Lists
165. Merge Two Sorted ListsDescription:Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted list should be made by splicing together the nodes of the two list...原创 2020-01-21 07:07:17 · 122 阅读 · 0 评论 -
380. Intersection of Two Linked Lists
380. Intersection of Two Linked ListsDescription:Write a program to find the node at which the intersection of two singly linked lists begins.ExampleExample 1:Input:A: a1 → a2↘c1 → c2...原创 2020-01-21 07:03:43 · 126 阅读 · 0 评论 -
105. Copy List with Random Pointer
35. Reverse Linked ListDescription:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list....原创 2020-01-21 06:38:59 · 137 阅读 · 0 评论 -
35. Reverse Linked List
35. Reverse Linked ListDescription:Reverse a linked list.ExampleExample 1:Input: 1->2->3->nullOutput: 3->2->1->nullExample 2:Input: 1->2->3->4->nullOutput: 4->...原创 2020-01-20 17:29:18 · 177 阅读 · 0 评论 -
Wiggle Sort I/II
508. Wiggle SortTag:Main Idea:Problem Type.State:Update Function:Initialization:Answer:Tips/Notes:Time/Space Cost:Time Cost: O(n)\ O(n) O(n)Space Cost: O(1)\ O(1)...原创 2020-01-19 12:55:46 · 160 阅读 · 0 评论 -
5. Kth Largest Element
5. Kth Largest ElementTag:Main Idea:It’s not recommended to sort the array, because it’s time-costing.State:Update Function:Initialization:Answer:Tips/Notes:Time/Space Cost:Time Co...原创 2020-01-19 07:23:30 · 175 阅读 · 0 评论 -
Continuous Subarray Sum I/II
402. Continuous Subarray SumsTag:Main Idea:Problem Type.State:Update Function:Initialization:Answer:Tips/Notes:Time/Space Cost:Time Cost: O(n)\ O(n) O(n)Space Cost: &nb...原创 2020-01-19 06:04:22 · 181 阅读 · 0 评论 -
Subarray Sum I/II/III
138. Subarray SumTag:Hash Table, Subarray.Main Idea:Problem Type.State:Update Function:Initialization:Answer:Tips/Notes:Time/Space Cost:Time Cost: O(n)\ O(n) O(n)Code:...原创 2020-01-18 13:29:01 · 206 阅读 · 0 评论 -
119. Edit Distance
119. Edit DistanceTag:Dynamic ProblemMain Idea:DP-Match Problem.State:dp[i][j] : the minimum number of steps of converting s1(0,i) to s2(0, j).Update Function:IF s1[i] == s2[j], THEN dp[i][j]...原创 2020-01-12 04:45:18 · 123 阅读 · 0 评论 -
77. Longest Common Subsequence
77. Longest Common SubsequenceTag:Dynamic ProblemMain Idea:DP-Match Problem. As there are two strings s1, s2, let n be the length of s1, m be the length of s2. For the problem, 0 <= i < n, 0...原创 2020-01-12 03:58:23 · 140 阅读 · 0 评论 -
430. Scramble String
430. Scramble StringTag:Dynamic ProblemMain Idea:DP-Range Problem. In this problem, we the major part is how to reduce the large problem into small problem.As there are two strings, s1 and s2. Th...原创 2020-01-12 01:42:25 · 118 阅读 · 0 评论 -
168. Burst Balloons
168. Burst BalloonsTag:Dynamic ProblemMain Idea:DP-range ProblemBefore dive into the DP problem, we will process the vector first. What we are going to do to insert at both the front and the end ...原创 2020-01-12 00:05:30 · 93 阅读 · 0 评论 -
Stone Game
Stone GameTag:Dynamic ProblemMain Idea:DP-Range Problem.State:For 0 <= i < j <= n, dp[i][j] represents the minimum cost to pile the stone from i to j.Update Function:Firstly, we ...原创 2020-01-11 07:20:06 · 123 阅读 · 0 评论 -
Coins in a Line I/II/III
394. Coins in a LineTag:Dynamic ProblemMain Idea:DP-Game Problem. This problem can have multiple solutions.Solution 1:Assuming player A is the first one to take the coins. Let dp[i]\ dp[i]...原创 2020-01-10 14:43:38 · 223 阅读 · 0 评论 -
Longest Increasing Subsequence I/II
76. Longest Increasing SubsequenceTag:Dynamic ProblemMain Idea:Classic DP Problem. Let dp[i]\ dp[i] dp[i] represents the number of longest increasing subsequence at the position i. For ...原创 2020-01-09 15:42:09 · 134 阅读 · 0 评论 -
392. House Robber I/II
392. House RobberTag:Dynamic ProblemMain Idea:Rolling array problem. To solve the DP problem, we need to consider the base cases and update function.In this problem, let rob[i]\ rob[i] ...原创 2020-01-08 13:13:00 · 114 阅读 · 0 评论 -
436. Maximal Square
436. Maximal SquareTag:Dynamic Problem.Main Idea:2D Matrix DP Problem. Let dp[i][j]\ dp[i][j] dp[i][j] means the maximum square edge. The first thing to do is initialization, for all &...原创 2020-01-09 08:49:51 · 98 阅读 · 0 评论