
Lintcode刷题
2Young2Simple
这个作者很懒,什么都没留下…
展开
-
Lintcode 994. Contiguous Array (Medium) (Python)
Contiguous ArrayDescription:Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.Example Example 1:Input: [0,1] Output: 2 Explanation: [0, 1] ...原创 2018-09-04 13:24:10 · 189 阅读 · 0 评论 -
Lintcode 392. House Robber (Medium) (Python)
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 of...原创 2018-09-09 10:43:24 · 140 阅读 · 0 评论 -
Lintcode 424. Evaluate Reverse Polish Notation (Medium) (Python)
Evaluate Reverse Polish NotationDescription:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another ex...原创 2018-09-09 11:09:12 · 117 阅读 · 0 评论 -
Lintcode 88. Lowest Common Ancestor of a Binary Tree (Medium) (Python)
Lowest Common Ancestor of a Binary TreeDescription:Given the root and two nodes in a Binary Tree. Find the lowest common ancestor(LCA) of the two nodes.The lowest common ancestor is the node wit...原创 2018-09-04 01:27:00 · 307 阅读 · 0 评论 -
Lintcode 191. Maximum Product Subarray (Medium) (Python)
Maximum Product SubarrayDescription:Find the contiguous subarray within an array (containing at least one number) which has the largest product.Example For example, given the array [2,3,-2,4], ...原创 2018-09-09 14:22:08 · 151 阅读 · 0 评论 -
Lintcode 15. Permutations (Medium) (Python)
PermutationsDescription:Given a list of numbers, return all possible permutations.Example For nums = [1,2,3], the permutations are:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2]...原创 2018-09-09 14:37:35 · 179 阅读 · 0 评论 -
Lintcode 62. Search in Rotated Sorted Array (Medium) (Python)
Search in Rotated Sorted ArrayDescription: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).You are given a target valu...原创 2018-09-06 06:43:13 · 168 阅读 · 0 评论 -
Lintcode 512. Decode Ways (Medium) (Python)
Decode WaysDescription:A message containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containin...原创 2018-09-06 08:23:35 · 198 阅读 · 0 评论 -
Lintcode 124. Longest Consecutive Sequence (Medium) (Python)
Longest Consecutive SequenceDescription:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Example Given [100, 4, 200, 1, 3, 2], The longest cons...原创 2018-09-06 12:35:45 · 265 阅读 · 0 评论 -
Lintcode 162. Set Matrix Zeroes (Medium) (Python)
Description:Code:原创 2018-09-04 00:22:11 · 114 阅读 · 0 评论 -
Lintcode 1195. Find Largest Value in Each Tree Row (Medium) (Python)
Find Largest Value in Each Tree RowDescription:You need to find the largest value in each row of a binary tree.Example Input: [1,3,2,5,3,#,9] Output: [1, 3, 9]Code:"""Definition of Tree...原创 2018-09-09 04:04:51 · 223 阅读 · 0 评论 -
Lintcode 442. Implement Trie (Prefix Tree) (Medium) (Python)
Implement TrieDescription:Implement a trie with insert, search, and startsWith methods.Example insert(“lintcode”) search(“code”) false startsWith(“lint”) true ...原创 2018-09-08 08:39:18 · 214 阅读 · 0 评论 -
Lintcode 419. Roman to Integer (Medium) (Python)
Roman to IntegerDescription:Given a roman numeral, convert it to an integer.The answer is guaranteed to be within the range from 1 to 3999.Example IV -> 4XII -> 12XXI -> 21XCIX...原创 2018-09-05 11:32:11 · 166 阅读 · 0 评论 -
Lintcode 171. Anagrams (Medium) (Python)
AnagramsDescription:Given an array of strings, return all groups of strings that are anagrams.Example Given [“lint”, “intl”, “inlt”, “code”], return [“lint”, “inlt”, “intl”].Given [“ab”, “ba”...原创 2018-09-05 12:01:21 · 240 阅读 · 0 评论 -
Lintcode 223. Palindrome Linked List (Medium) (Python)
Palindrome Linked ListDescription:Implement a function to check if a linked list is a palindrome.Example Given 1->2->1, return trueChallenge Could you do it in O(n) time and O(1) spa...原创 2018-09-03 08:27:59 · 164 阅读 · 0 评论 -
Lintcode 161. Rotate Image (Medium) (Python)
Description:Code:原创 2018-09-03 09:10:44 · 183 阅读 · 0 评论 -
Lintcode 418. Integer to Roman (Medium) (Python)
Integer to RomanDescription:Given an integer, convert it to a roman numeral.The number is guaranteed to be within the range from 1 to 3999.Example 4 -> IV12 -> XII21 -> XXI99 -...原创 2018-09-08 23:28:14 · 182 阅读 · 0 评论 -
Lintcode 388. Permutation Sequence (Medium) (Python)
Permutation SequenceDescription:Given n and k, return the k-th permutation sequence.Example For n = 3, all permutations are listed as follows:“123” “132” “213” “231” “312” “321” If k = ...原创 2018-09-09 01:20:02 · 118 阅读 · 0 评论 -
Lintcode 95. Validate Binary Search Tree (Medium) (Python)
Validate Binary Search TreeDescription:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only node...原创 2018-09-03 11:19:33 · 173 阅读 · 0 评论 -
Lintcode 61. Search for a Range (Medium) (Python)
Search for a RangeDescription:Given a sorted array of n integers, find the starting and ending position of a given target value.If the target is not found in the array, return [-1, -1].Example...原创 2018-09-10 02:07:25 · 159 阅读 · 0 评论 -
Lintcode 1001. Asteroid Collision (Medium) (Python)
Asteroid CollisionDescription:We are given an array asteroids of integers representing asteroids in a row.For each asteroid, the absolute value represents its size, and the sign represents its d...原创 2018-09-12 08:57:16 · 351 阅读 · 0 评论 -
Lintcode 617. Maximum Average Subarray II (Medium) (Python)
Maximum Average Subarray IIDescription:Given an array with positive and negative numbers, find the maximum average subarray which length should be greater or equal to given length k.Example Giv...原创 2018-09-12 16:20:07 · 334 阅读 · 0 评论 -
Lintcode 159. Find Minimum in Rotated Sorted Array (Medium) (Python)
Find Minimum in Rotated Sorted ArrayDescription: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 elem...原创 2018-09-14 05:21:07 · 209 阅读 · 0 评论 -
Lintcode 545. Top k Largest Numbers II (Medium) (Python)
Top k Largest Numbers IIDescription:Implement a data structure, provide two interfaces:add(number). Add a new number in the data structure. topk(). Return the top k largest numbers in this data...原创 2018-09-14 06:33:40 · 259 阅读 · 0 评论 -
Lintcode 1259. Integer Replacement (Medium) (Python)
Integer ReplacementDescription:Given a positive integer n and you can do operations as follow:1.If n is even, replace n with n/2. 2.If n is odd, you can replace n with either n + 1 or n - 1.W...原创 2018-09-11 10:31:25 · 165 阅读 · 0 评论 -
Lintcode 1076. Minimum ASCII Delete Sum for Two Strings (Python) (Medium)
Minimum ASCII Delete Sum for Two StringsDescription:Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.ExampleExample 1:Input: s1 = “sea”, s2 = “e...原创 2018-09-30 11:16:30 · 183 阅读 · 0 评论 -
Lintcode 65. Median of two Sorted Arrays (Hard) (Python)
Median of two Sorted ArraysDescription:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays.ExampleGiven A=[1,2,3,4,5,6] and B=[2,3,4,5], the ...原创 2018-09-30 12:45:11 · 189 阅读 · 0 评论 -
Lintcode 86. Binary Search Tree Iterator (Hard) (Python)
Binary Search Tree IteratorDescription:Design an iterator over a binary search tree with the following rules:Elements are visited in ascending order (i.e. an in-order traversal)next() and hasNext(...原创 2018-09-30 13:59:52 · 219 阅读 · 0 评论 -
Lintcode 131. The Skyline Problem (Super Hard) (Python) (未完成)
The Skyline ProblemDescription:Given N buildings in a x-axis,each building is a rectangle and can be represented by a triple (start, end, height),where start is the start position on x-axis, end is ...原创 2018-09-30 17:57:18 · 435 阅读 · 0 评论 -
Lintcode 134. LRU Cache (Medium) (Python)
LRU CacheDescription:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be posi...原创 2018-09-30 18:39:38 · 265 阅读 · 0 评论 -
Lintcode 544. Top k Largest Numbers (Medium) (Python)
Top k Largest NumbersDescription:Given an integer array, find the top k largest numbers in it.Example Given [3,10,1000,-99,4,100] and k = 3. Return [1000, 100, 10].Code:class Solution:...原创 2018-09-14 03:44:27 · 322 阅读 · 0 评论 -
Lintcode 383. Container With Most Water (Medium) (Python)
Container With Most WaterDescription: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 lin...原创 2018-09-14 02:57:56 · 197 阅读 · 0 评论 -
Lintcode 16. Permutations II (Medium) (Python)
Permutations IIDescription:Given a list of numbers with duplicate number in it. Find all unique permutations.Example For numbers [1,2,2] the unique permutations are:[ [1,2,2], [2,1,2], ...原创 2018-09-10 09:57:36 · 180 阅读 · 0 评论 -
Lintcode 78. Longest Common Prefix (Medium) (Python)
Longest Common PrefixDescription:Given k strings, find the longest common prefix (LCP).Example For strings “ABCD”, “ABEF” and “ACEF”, the LCP is “A”For strings “ABCDEFG”, “ABCEFG” and “ABCEFA...原创 2018-09-10 11:31:38 · 141 阅读 · 0 评论 -
Lintcode 137. Clone Graph (Medium) (Python)
Clone GraphDescription:Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.How we serialize an undirected graph:Nodes are labeled uniquely.We use #...原创 2018-09-07 12:37:39 · 185 阅读 · 0 评论 -
Lintcode 421. Simplify Path (Medium) (Python)
Simplify PathDescription:Given an absolute path for a file (Unix-style), simplify it.Example “/home/”, => “/home”“/a/./b/../../c/”, => “/c”Challenge Did you consider the case where p...原创 2018-09-07 15:15:07 · 148 阅读 · 0 评论 -
Lintcode 178. Graph Valid Tree (Medium) (Python)
Graph Valid TreeDescription:Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree....原创 2018-09-11 02:20:34 · 383 阅读 · 0 评论 -
Lintcode 148. Sort Colors (Medium) (Python)
Sort ColorsDescription:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, ...原创 2018-09-11 03:16:09 · 167 阅读 · 0 评论 -
Lintcode 904. Plus One Linked List (Medium) (Python)
Plus One Linked ListDescription:Given a non-negative integer represented as non-empty a singly linked list of digits, plus one to the integer.You may assume the integer do not contain any leadin...原创 2018-09-13 12:00:29 · 139 阅读 · 0 评论 -
Lintcode 886. Convex Polygon (Medium) (Python)
Convex PolygonDescription:Given a list of points that form a polygon when joined sequentially, find if this polygon is convex (Convex polygon definition).Example Given points = [[0, 0], [0, 1],...原创 2018-09-13 13:55:53 · 235 阅读 · 0 评论