
LeetCode
文章平均质量分 52
hale1007
ZJUCS小硕一枚,进阶中的菜鸟
展开
-
[LeetCode] Longest Palindromic Substring
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.原创 2014-11-07 01:21:09 · 453 阅读 · 0 评论 -
[LeetCode] Restore IP Addresses
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 do原创 2014-05-03 17:52:07 · 441 阅读 · 0 评论 -
[LeetCode] Generate Parentheses
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:"((()))", "(()())", "(())()", "()(())", "()()()原创 2014-05-09 16:43:20 · 397 阅读 · 0 评论 -
[LeetCode] Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2014-04-30 19:21:19 · 449 阅读 · 0 评论 -
[LeetCode] Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.原创 2014-04-30 16:55:56 · 414 阅读 · 0 评论 -
[LeetCode] Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2014-10-16 20:53:50 · 362 阅读 · 0 评论 -
[LeetCode] Add Two Numbers
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原创 2014-10-16 17:29:24 · 402 阅读 · 0 评论 -
[LeetCode] Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad原创 2014-03-27 21:28:29 · 529 阅读 · 0 评论 -
[LeetCode] Rotate Image
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?原创 2014-05-01 14:42:49 · 377 阅读 · 0 评论 -
[LeetCode] Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2014-05-01 20:31:08 · 365 阅读 · 0 评论 -
[LeetCode] Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tr原创 2014-05-01 21:22:09 · 520 阅读 · 0 评论 -
[LeetCode] Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3,原创 2014-05-03 23:03:55 · 438 阅读 · 0 评论 -
[LeetCode] ZigZag Conversion
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 I原创 2014-05-04 10:10:19 · 450 阅读 · 0 评论 -
[LeetCode] Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If t原创 2014-04-30 19:23:09 · 370 阅读 · 0 评论 -
[LeetCode] Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2014-04-02 10:16:38 · 477 阅读 · 0 评论 -
[LeetCode] Divide Two Integers
Divide two integers without using multiplication, division and mod operator.原创 2014-10-16 22:23:20 · 390 阅读 · 0 评论 -
[LeetCode] Longest Substring Without Repeating Characters
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. Fo原创 2014-10-16 16:53:04 · 452 阅读 · 0 评论 -
[LeetCode] Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?/** * Definition for singly-linke原创 2014-03-26 23:30:23 · 515 阅读 · 0 评论 -
[LeetCode] Remove Nth Node From End of List
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 the end, the l原创 2014-05-09 19:32:38 · 401 阅读 · 0 评论 -
[LeetCode] Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.原创 2014-05-01 19:00:43 · 415 阅读 · 0 评论 -
[LeetCode] Best Time to Buy and Sell Stock II
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 as many transactions as you like (ie, buy on原创 2014-05-01 10:38:24 · 492 阅读 · 0 评论 -
[LeetCode] Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?原创 2014-05-01 11:30:51 · 351 阅读 · 0 评论 -
[LeetCode] Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.原创 2014-05-13 11:54:32 · 953 阅读 · 0 评论 -
[LeetCode] Insertion Sort List
Sort a linked list using insertion sort.原创 2014-10-15 22:46:22 · 472 阅读 · 0 评论 -
[LeetCode] Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]原创 2014-05-01 10:57:51 · 330 阅读 · 0 评论 -
[LeetCode] Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 /原创 2014-05-01 20:15:28 · 378 阅读 · 0 评论 -
[LeetCode] Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [原创 2014-05-03 15:02:42 · 385 阅读 · 0 评论 -
[LeetCode] Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".原创 2014-05-03 15:28:32 · 404 阅读 · 0 评论 -
[LeetCode] Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is def原创 2014-05-09 17:10:25 · 508 阅读 · 0 评论 -
[LeetCode] Best Time to Buy and Sell Stock
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 (ie, buy one and sell one share of the stock),原创 2014-05-01 10:36:39 · 474 阅读 · 0 评论 -
[LeetCode] Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2014-04-30 22:24:15 · 453 阅读 · 0 评论 -
[LeetCode] Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.class Solution {public: int sqrt(int x) { if(x == 0) return 0; double eps = 1e-6; double val = (原创 2014-04-02 10:37:28 · 420 阅读 · 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 arr原创 2014-05-09 20:27:55 · 529 阅读 · 0 评论 -
[LeetCode] Sort List
Sort a linked list in O(n log n) time using constant space complexity.比较蛋疼,我取巧了。可能不合题意。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next;原创 2014-03-27 01:37:13 · 531 阅读 · 0 评论 -
[LeetCode] Spiral Matrix
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原创 2014-05-03 14:35:49 · 401 阅读 · 0 评论 -
[LeetCode] Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * struct ListNode { * int val; *原创 2014-03-26 23:35:55 · 493 阅读 · 0 评论 -
[LeetCode] Best Time to Buy and Sell Stock III
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 two transactions.Note:You may原创 2014-05-01 10:39:50 · 433 阅读 · 0 评论 -
[LeetCode] Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".What constitutes a word?A sequence of non-space characters con原创 2014-03-27 00:21:56 · 547 阅读 · 0 评论 -
[LeetCode] Next Permutation
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 o原创 2014-05-03 15:56:27 · 400 阅读 · 0 评论 -
[LeetCode] 3Sum
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原创 2014-10-23 11:40:40 · 344 阅读 · 0 评论