LeetCode
junchen1992
Be the change that you wish to see in the world.
展开
-
LeetCode #1996. The Number of Weak Characters in the Game
[LeetCode]1996. The Number of Weak Characters in the Gameclass Solution: def numberOfWeakCharacters(self, properties: List[List[int]]) -> int: """ Time Complexity: O(n * log(n)) Space Complexity: O(1) Where:原创 2021-09-09 19:54:50 · 104 阅读 · 0 评论 -
LeetCode #3: Longest Substring Without Repeating Characters
Problem Statement(Problem Link) Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb"原创 2016-08-27 11:09:26 · 418 阅读 · 0 评论 -
LeetCode #312: Burst Balloons
Problem Statement(Source) Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst ballo原创 2016-08-30 12:17:24 · 371 阅读 · 0 评论 -
LeetCode #99: Recover Binary Search Tree
Problem Statement(Source) Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure.Note: A solution using O(n) space is pretty straight forwar原创 2016-08-31 09:33:55 · 260 阅读 · 0 评论 -
LeetCode #382: Linked List Random Node
Problem Statement(Problem Link) Given a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen.Follow up: What if the linked li原创 2016-08-29 09:06:40 · 468 阅读 · 0 评论 -
LeetCode #132: Palindrome Partitioning II
Problem statementGiven a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = “aab”原创 2016-08-22 20:55:22 · 549 阅读 · 0 评论 -
LeetCode: 371. Sum of Two Integers
Original ProblemCalculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.Solutiondef原创 2016-08-22 07:15:42 · 229 阅读 · 0 评论 -
LeetCode #329: Longest Increasing Path in a Matrix
Problem Statement(Source) Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diago原创 2016-08-31 20:45:13 · 390 阅读 · 0 评论 -
LeetCode #41: First Missing Positive
Problem Statement(Source) Given an unsorted integer array, find the first missing positive integer.For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2.Your algorithm should run in O(n) time原创 2016-09-13 13:14:39 · 218 阅读 · 0 评论 -
LeetCode #273: Integer to English Words
Problem Statement(Source) Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231−12^{31} - 1.For example, 123 -> “One Hundred Twenty Three”原创 2016-09-02 14:59:24 · 255 阅读 · 0 评论 -
LeetCode #233: Number of Digit One
Problem StatementGiven an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example: Given n = 13, Return 6, because digit 1 occurred in原创 2016-09-02 20:01:32 · 279 阅读 · 0 评论 -
LeetCode #140: Word Break II
Problem Statement(Source)Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For examp原创 2016-09-03 13:07:28 · 276 阅读 · 0 评论 -
LeetCode #388: Longest Absolute File Path
Problem Statement(Source) Suppose we abstract our file system by a string in the following manner:The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext" represents:dir subdir1 subdir2 fil原创 2016-09-03 14:27:00 · 274 阅读 · 0 评论 -
LeetCode #87: Scramble String
Problem Statement(Source) Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = “great”: grea原创 2016-09-04 09:58:39 · 271 阅读 · 0 评论 -
LeetCode #188: Best Time to Buy and Sell Stock IV
Problem Statement(Source) Say you have an array for which the ithi^{th} element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transac原创 2016-09-04 11:42:56 · 229 阅读 · 0 评论 -
LeetCode #10: Regular Expression Matching
Problem Statement(Source) Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cove原创 2016-09-04 12:45:36 · 219 阅读 · 0 评论 -
LeetCode #1: Two Sum
Problem Statement(Problem Link) Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.E原创 2016-08-27 09:42:51 · 363 阅读 · 0 评论 -
LeetCode #167: Two Sum II - Input array is sorted
Problem Statement(Source) Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indi原创 2016-09-16 17:35:10 · 206 阅读 · 0 评论 -
LeetCode #153: Find Minimum in Rotated Sorted Array
Problem Statement(Source) Suppose a sorted array 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).Find the minimum element.You may assume no duplicate原创 2016-09-17 10:38:25 · 180 阅读 · 0 评论 -
LeetCode #162: Find Peak Element
Problem Statement(Source) A peak element is an element that is greater than its neighbours.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain m原创 2016-09-17 11:00:40 · 187 阅读 · 0 评论 -
LeetCode #187: Repeated DNA Sequences
Problem Statement(Source) All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated sequenc原创 2016-09-17 17:03:47 · 231 阅读 · 0 评论 -
LeetCode #201: Bitwise AND of Numbers Range
Problem Statement(Source) Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.For example, given the range [5, 7], you should return 4.A原创 2016-09-17 17:24:19 · 199 阅读 · 0 评论 -
LeetCode #56: Merge Intervals
Problem Statement(Source) Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].Solution# Definition for an inter原创 2016-09-17 21:43:44 · 187 阅读 · 0 评论 -
LeetCode #57: Insert Interval
Problem Statement(Source) Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to th原创 2016-09-17 22:01:47 · 354 阅读 · 0 评论 -
LeetCode #402: Remove K Digits
Problem StatementGiven a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.Note:The length of num is less than 105 and w原创 2016-09-18 16:03:57 · 560 阅读 · 0 评论 -
LeetCode #352: Data Stream as Disjoint Intervals
Problem Statement(Source) Given a data stream input of non-negative integers a1, a2, …, an, …, summarize the numbers seen so far as a list of disjoint intervals.For example, suppose the integers from t原创 2016-09-17 22:12:55 · 382 阅读 · 0 评论 -
[TODO] LeetCode #363: Max Sum of Rectangle No Larger Than K
Problem Statement(Source) Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k.Example:Given matrix = [ [1, 0, 1]原创 2016-09-04 14:38:24 · 244 阅读 · 0 评论 -
LeetCode #368: Largest Divisible Subset
Problem Statement(Source) Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If there are原创 2016-09-18 22:49:16 · 248 阅读 · 0 评论 -
[TODO] LeetCode #375: Guess Number Higher or Lower II
Problem Statement(Source) We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I’ll tell you whether th原创 2016-09-03 15:08:19 · 270 阅读 · 0 评论 -
LeetCode #318: Maximum Product of Word Lengths
Problem Statement(Source) Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will con原创 2016-09-19 11:51:42 · 211 阅读 · 0 评论 -
[TODO] LeetCode #300: Longest Increasing Subsequence
Problem Statement(Source) Given an unsorted array of integers, find the length of longest increasing subsequence.For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is原创 2016-09-19 12:03:11 · 194 阅读 · 0 评论 -
LeetCode #2: Add Two Numbers
Problem StatementYou are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and ret原创 2016-08-27 10:02:47 · 394 阅读 · 0 评论 -
LeetCode #321: Create Maximum Number
Problem Statement(Source) Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k <= m + n from digits of the two. The relative order of the d原创 2016-09-07 11:48:36 · 336 阅读 · 0 评论 -
LeetCode #40: Combination Sum II
Problem Statement(Source) 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原创 2016-09-20 15:59:17 · 258 阅读 · 0 评论 -
LeetCode #39. Combination Sum
Problem Statement(Source) Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen fr原创 2016-09-20 15:54:16 · 183 阅读 · 0 评论 -
LeetCode #216: Combination Sum III
Problem Statement(Source) Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.E原创 2016-09-20 16:07:23 · 205 阅读 · 0 评论 -
LeetCode #377: Combination Sum IV
Problem Statement(Source) Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]原创 2016-09-20 16:10:07 · 532 阅读 · 0 评论 -
LeetCode #316: Remove Duplicate Letters
Problem Statement(Source) Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest i原创 2016-09-20 16:55:59 · 231 阅读 · 0 评论 -
LeetCode #32: Longest Valid Parentheses
Problem Statement(Source) Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses su原创 2016-09-21 18:54:20 · 221 阅读 · 0 评论 -
LeetCode #169: Majority Element
Problem Statement(Source) Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and th原创 2016-09-22 11:07:38 · 216 阅读 · 0 评论