Leetcode
风澈云间
这个作者很懒,什么都没留下…
展开
-
[Leetcode]10. Regular Expression Matching @python
题目Implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input stri原创 2016-01-16 12:20:06 · 1372 阅读 · 0 评论 -
[Leetcode]188. Best Time to Buy and Sell Stock IV@python
题目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 complete at most k transactions.Note: You may not engag原创 2016-02-05 20:49:23 · 620 阅读 · 0 评论 -
[Leetcode] 179. Largest Number @python
题目Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be very larg原创 2016-02-05 17:00:05 · 2717 阅读 · 0 评论 -
[Leetcode]174. Dungeon Game @python
题目The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially po原创 2016-02-05 16:25:48 · 686 阅读 · 0 评论 -
[Leetcode]166. Fraction to Recurring Decimal @python
题目Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.For ex原创 2016-02-05 15:09:37 · 699 阅读 · 0 评论 -
[Leetcode]152. Maximum Product Subarray @python
题目Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest pro原创 2016-02-05 14:30:35 · 691 阅读 · 0 评论 -
[Leetcode]149. Max Points on a Line @python
题目Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.题目要求给定n个2维平面上的点,找到在同一直线上最多的点数。解题思路在同一直线上要求所有点的斜率相同且经过同一个点。同时要考虑,斜率可能为无穷大,也有可能两个点为同一个点。代码# Definition原创 2016-02-05 14:06:11 · 787 阅读 · 1 评论 -
[Leetcode]2.Add Two Numbers @python
题目You 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 return it as a lin原创 2016-01-11 21:06:28 · 251 阅读 · 0 评论 -
[Leetcode]142. Linked List Cycle II @python
题目Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up: Can you solve it without using extra space?题目要求给定一个链表,如果原创 2016-01-28 12:08:55 · 1031 阅读 · 0 评论 -
[Leetcode]201. Bitwise AND of Numbers Range @python
题目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.题目要求给定m和n要求m到n的所有数字相与的结果。原创 2016-02-05 21:05:03 · 918 阅读 · 0 评论 -
[Leetcode]211. Add and Search Word - Data structure design @python
题目Design a data structure that supports the following two operations:void addWord(word) bool search(word) search(word) can search a literal word or a regular expression string containing only letters原创 2016-02-05 22:00:44 · 881 阅读 · 0 评论 -
[Leetcode]214. Shortest Palindrome@python
题目Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For example原创 2016-02-25 22:25:36 · 1053 阅读 · 0 评论 -
[Leetcode] 212. Word Search @python
题目Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizo原创 2016-02-25 19:59:33 · 1291 阅读 · 0 评论 -
[Leetcode]6. ZigZag Conversion @python
题目The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N原创 2016-01-13 00:32:16 · 1697 阅读 · 0 评论 -
[Leetcode]5.Longest Palindromic Substring @ Python
题目Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.题目要求给定一个字符串s,找出字符串s中最大的回文原创 2016-01-12 20:33:49 · 256 阅读 · 0 评论 -
[Leetcode] 1.Two Sum @python
[Leetcode] Two Sum @python题目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 ad原创 2016-01-11 20:24:27 · 370 阅读 · 0 评论 -
[Leetcode]4. Median of Two Sorted Arrays @python
题目There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).题目要求有两个排好序的数组nums1,nums2,找到这原创 2016-01-12 20:03:48 · 475 阅读 · 0 评论 -
[Leetcode]3. Longest Substring Without Repeating Characters @python
题目Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For原创 2016-01-12 19:05:20 · 424 阅读 · 0 评论 -
[Leetcode]146. LRU Cache @python
题目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 positive) of the key if the原创 2016-01-29 13:56:46 · 1459 阅读 · 0 评论 -
[Leetcode]126. Word Ladder II python
题目Given two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a time Each原创 2016-01-24 23:42:52 · 2458 阅读 · 0 评论 -
[Leetcode]127. Word Ladder@python
题目Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a tim原创 2016-01-24 22:33:15 · 1577 阅读 · 0 评论 -
[Leetcode] 50. Pow(x, n) @python
题目Implement pow(x, n).题目要求实现x的n次幂。解题思路此题参考南郭子綦 自己想了很久,没想到用这么几行代码就搞定了。 采用递归来实现二分。分以下四种情况考虑: 1. n ==0 ,返回1.0 2. n < 0, 返回1/pow(x,-n) 3. n % 2 == 0,返回pow(x*x,n/2) 4. n % 2 == 1,返回pow(x*x,n/2) * x$代码原创 2016-01-18 20:58:37 · 761 阅读 · 0 评论 -
[Leetcode]43. Multiply Strings @python
题目Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.题目要求给定两个用字符串表示的数字,进行乘法运算,并且返回结果用字符串表示。解题思路先将原创 2016-01-17 13:12:47 · 1237 阅读 · 0 评论 -
[Leetcode]36. Valid Sudoku@python
题目Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. A partially filled sudoku原创 2016-01-17 12:13:06 · 474 阅读 · 0 评论 -
[Leetcode]32. Longest Valid Parentheses @python
题目Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, which h原创 2016-01-17 11:30:43 · 1042 阅读 · 0 评论 -
[Leetcode] 15.3Sum @python
题目Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: Elements in a triplet (a,b,c) must be原创 2016-01-16 23:16:51 · 286 阅读 · 0 评论 -
[Leetcode]30. Substring with Concatenation of All Words @python
题目You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and w原创 2016-01-16 22:19:45 · 1045 阅读 · 0 评论 -
[Leetcode]29. Divide Two Integers @python
题目Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.题目要求除法运算,但是不能用编程语言提供的乘法、除法和取模运算,即只能用加法和减法实现。为了加速运算,可以依次将被除数减去1,2,4,8,..倍的除数。所以这里可以用移位来进一步原创 2016-01-16 16:48:08 · 1684 阅读 · 0 评论 -
[Leetcode]23. Merge k Sorted Lists @python
题目Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目要求将k个有序的列表组合成一个大的有序列表,并分析实现的复杂度解题思路此题参考kitt blog,使用小根堆结构进行实现。 先将所有列表按照第一个元素的大小放入小根堆中,然后每次取回最小的元素的列原创 2016-01-16 15:32:14 · 1829 阅读 · 0 评论 -
[Leetcode]54. Spiral Matrix @python
题目Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] You原创 2016-01-18 21:27:37 · 1344 阅读 · 0 评论 -
[Leetcode]61. Rotate List @python
题目Given a list, rotate the list to the right by k places, where k is non-negative.For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.题目要求给定链表和非负数k,将链表内的元素向右移动k位。解题思路解题思路参考南郭原创 2016-01-18 22:44:37 · 391 阅读 · 0 评论 -
[Leetcode]105. Construct Binary Tree from Preorder and Inorder Traversal@python
题目Given preorder and inorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.题目要求给定对一个binary-tree的前序遍历和中序遍历。重建二叉树。解题思路前序遍历的第一个值为根节点的值,在中序遍历原创 2016-01-24 14:17:16 · 855 阅读 · 0 评论 -
[Leetcode] 98. Validate Binary Search Tree @python
题目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 nodes with keys less than the node’s key. The rig原创 2016-01-24 13:49:55 · 670 阅读 · 0 评论 -
[Leetcode]97. Interleaving String @python
题目Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example, Given: s1 = “aabcc”, s2 = “dbbca”,When s3 = “aadbbcbcac”, return true. When s3 = “aadbbbaccc”, return fal原创 2016-01-24 12:40:50 · 496 阅读 · 0 评论 -
[Leetcode]91. Decode Ways@python
题目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 containing digits, determine the total number原创 2016-01-23 18:38:34 · 1312 阅读 · 0 评论 -
[leetcode]87. Scramble String @python
题目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”: great / \ gr原创 2016-01-23 13:48:26 · 640 阅读 · 0 评论 -
[Leetcode]Search in Rotated Sorted Array II
题目Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the array.原创 2016-01-23 13:19:42 · 241 阅读 · 0 评论 -
[Leetcode]76. Minimum Window Substring @python
题目Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example, S = “ADOBECODEBANC” T = “ABC” Minimum window is “BANC”.Note原创 2016-01-21 21:52:24 · 1367 阅读 · 0 评论 -
[Leetcode]68. Text Justification @python
题目Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that is,原创 2016-01-20 22:14:43 · 1017 阅读 · 0 评论 -
[Leetcode]220. Contains Duplicate III @python
题目Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j i原创 2016-02-26 23:49:35 · 1600 阅读 · 0 评论