![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 63
hyperbolechi
这个作者很懒,什么都没留下…
展开
-
5.Longest Palindromic Substring Leetcode 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.这题有两种解法,第一种是一一把所有序列挑原创 2015-01-27 12:46:44 · 690 阅读 · 0 评论 -
3.Longest Substring Without Repeating Characters Leetcode 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原创 2015-01-27 05:11:05 · 381 阅读 · 0 评论 -
1.Two Sum Leetcode 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 add up to the target, w原创 2015-01-27 01:04:51 · 811 阅读 · 0 评论 -
2.Add Two Numbers Leetcode 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 link原创 2015-01-27 01:09:51 · 466 阅读 · 0 评论 -
6. ZigZag Conversion Leetcode 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 NA P L S原创 2015-01-28 02:21:14 · 1293 阅读 · 0 评论 -
8. String to Integer (atoi) Leetcode Python
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2015-01-28 04:20:27 · 875 阅读 · 0 评论 -
9. Palindrome Number Leetcode Python
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of c原创 2015-01-28 05:00:02 · 477 阅读 · 0 评论 -
10.Container With Most Water Leetcode Python
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 line i is at (i, ai) and (i, 0). Find two原创 2015-01-28 05:36:02 · 397 阅读 · 0 评论 -
15. 3Sum Leetcode 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) mu原创 2015-01-17 08:47:03 · 1296 阅读 · 0 评论 -
16. 3Sum Closest Leetcode Python
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly原创 2015-01-17 10:10:08 · 1511 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number Leetcode Python
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Inpu原创 2015-01-28 10:47:52 · 1950 阅读 · 0 评论 -
4.Median of Two Sorted Arrays Leetcode Python
There are two sorted arrays A and B 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)).这题的一种O(m+n)的解法是mergesort的一步,依次比较两原创 2015-01-27 11:26:07 · 667 阅读 · 0 评论 -
7. Reverse Integer Leetcode Python
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321这里需要考虑几种边界条件,1.reverse完后的值大于+-2^32这时返回02.负数的处理先按照正数来做,最后再返回负数。代码如下class Solution: # @retu原创 2015-01-28 01:55:26 · 392 阅读 · 0 评论 -
13. Roman to Integer Leetcode Python
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.这题的做法和前面一体interger to roman 类似 建一个dictionary 去查询。 1.先把string 反转2. 用一个last去保存上一次的di原创 2015-01-30 09:28:30 · 600 阅读 · 0 评论 -
20. Valid Parentheses Leetcode Python
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all vali原创 2015-01-29 11:21:17 · 575 阅读 · 0 评论 -
27. Remove Element Leetcode Python
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.1原创 2015-01-29 11:53:34 · 1523 阅读 · 0 评论 -
96. Unique Binary Search Trees Leetcode
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's.这道题考查BST的构造。 构造BST只要满足中序遍历有序即可,当array=[原创 2015-01-15 10:09:04 · 512 阅读 · 0 评论 -
12. Integer to Roman Leetcode Python
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.建两个list依次match 罗马数字。 比较特殊的是 一些有两位的罗马数字。来自http://www.cnblogs.com/zuoyuan/p/377958原创 2015-01-30 09:23:11 · 792 阅读 · 0 评论 -
101. Symmetric Tree Leetcode Python
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2015-01-30 07:28:30 · 2385 阅读 · 0 评论 -
18. 4Sum Leetcode Python
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in原创 2015-01-17 11:55:43 · 1761 阅读 · 0 评论 -
21. Generate Parentheses Leetcode Python
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "原创 2015-01-29 11:28:24 · 873 阅读 · 0 评论 -
22. Merge k Sorted Lists Leetcode Python
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.假设平均linklist长度为m1. 用一个hashtable 将k 个linklist的头存进去需要 k 2.将hashtable里面的node的最小依次取出来加到新的Linklist后原创 2015-01-29 11:40:38 · 567 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array Leetcode Python
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 space for another array, you must do this in place wi原创 2015-01-29 11:50:33 · 720 阅读 · 0 评论 -
24. Swap Nodes in Pairs Leetcode Python
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant spac原创 2015-01-29 11:44:46 · 595 阅读 · 0 评论 -
19. Remove Nth Node From End of List Leetcode Python
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from th原创 2015-01-29 11:11:56 · 698 阅读 · 0 评论 -
62. Unique Path Leetcode Python
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach th原创 2015-01-30 11:57:48 · 1001 阅读 · 0 评论 -
135. Candy Leetcode Python
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on原创 2015-01-19 21:28:48 · 536 阅读 · 0 评论 -
31. Next Permutation Leetcode Python
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2015-01-22 06:43:06 · 812 阅读 · 0 评论 -
Gray Code Leetcode Python
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2015-01-15 05:27:49 · 650 阅读 · 0 评论 -
Merge Sorted Array Leetcode Python
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements fro原创 2015-01-15 05:01:40 · 492 阅读 · 0 评论 -
Restore IP Address Leetcode Python
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2015-01-15 09:00:05 · 529 阅读 · 0 评论 -
Recovery Binary Search Tree Leetcode Python
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.题目要求找到BST中被swap的两个节点并把它们复原,这里考虑到是BST 我们可以用Inorder traverse,如果没有被调换之前的所有节点值满足序号从小原创 2015-01-15 22:43:48 · 720 阅读 · 0 评论 -
Employees Earning More Than Their Managers Leetcode SQL
The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.+----+-------+--------+-----------+| Id | Name | Salar原创 2015-01-16 13:15:48 · 1176 阅读 · 0 评论 -
Validate Binary Search Tree Leetcode 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 ke原创 2015-01-15 23:20:15 · 668 阅读 · 0 评论 -
Combine Two Tables Leetcode
able: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------------+---------+Pers原创 2015-01-15 10:21:30 · 898 阅读 · 1 评论 -
41. First Missing Positive Leetcode Python
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 and uses cons原创 2015-02-03 04:40:20 · 1426 阅读 · 0 评论 -
63. Unique Path II Leetcode Python
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in th原创 2015-02-04 04:28:29 · 861 阅读 · 0 评论 -
174. Dungeon Game Leetcode 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 p原创 2015-01-17 03:18:35 · 1878 阅读 · 0 评论 -
48. Rotate Image Leetcode Python
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?这题是要定义一个Layer 逐层 交换ABCDtemp=A原创 2015-02-03 12:54:03 · 849 阅读 · 0 评论 -
54. Spiral Matrix Leetcode 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原创 2015-02-03 23:32:40 · 681 阅读 · 0 评论