Nov 26, 2020Member-onlyLeetcode Problem 121&122&123. Best Time to Buy and Sell Stock I/II/ IIIProblem 121: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. Note…4 min read

Nov 25, 2020Member-onlyLeetcode DP(Dynamic Programming)One-dimensional DP: Clear thinking is the most important because each question varies greatly. Longest Valid Parentheses. Find the length of the longest valid substring of a string that contains only “(“ and “)”. Valid means that all the parentheses in the substring match correctly. Maximum Subarray. What is the maximum value of…3 min read

Nov 25, 2020Member-onlyLeetcode Algorithm: Problem 20 & 22 (Totally different)Problem 20. Valid Parentheses Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: 1. Open brackets must be closed by the same type of brackets. 2. Open brackets must be closed in the correct order. …3 min read

Nov 23, 2020Member-onlyLeetcode Algorithm Problem17: Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example 1: …2 min read

Nov 23, 2020Member-onlyLeetcode Algorithm 18: 4SumGiven an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Notice that the solution set…1 min read

Nov 23, 2020Member-onlyLeetcode Problem 15: 3SumGiven 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. Notice that the solution set must not contain duplicate triplets. Example 1: Input…1 min read

Nov 22, 2020Member-onlyLeetcode Problem 12: Integer to RomanRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written…Leetcode2 min read

Nov 22, 2020Member-onlyLeetcode Algorithm 11. Container With Most WaterLeetcode Algorithm 11. Container With Most Water 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 the line i is at (i, ai) and (i, 0). …2 min read

Nov 21, 2020Member-onlyLeetcode Algorithm Problem 8. String to Integer (atoi)Leetcode Algorithm Problem 8. String to Integer (atoi) Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. …Leetcode2 min read

Nov 21, 2020Member-onlyLeeetcode Problem 7. Reverse IntegerLeeetcode Problem 7. Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. …Leetcode1 min read