
LeetCode
文章平均质量分 76
_王川
屌丝程序员
展开
-
LeetCode OJ:Clone Graph
Clone GrapClone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as原创 2014-01-15 21:59:12 · 1022 阅读 · 0 评论 -
LeetCode OJ:Surrounded Regions
Surrounded Regions Total Accepted: 3163 Total Submissions: 22161My SubmissionsGiven a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by f原创 2014-01-16 23:24:28 · 826 阅读 · 0 评论 -
LeetCode OJ:Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, convert it to a height balanced BST.算法思想:每次找寻中间的元素作为父亲节点/** * Definit原创 2014-01-22 03:04:42 · 1120 阅读 · 0 评论 -
LeetCode OJ:Construct Binary Tree from Preorder and Inorder Traversal
Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in th原创 2014-01-22 17:20:43 · 1040 阅读 · 0 评论 -
LeetCode OJ:Same Tree
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 va原创 2014-01-22 18:29:03 · 724 阅读 · 0 评论 -
LeetCode OJ:Unique Binary Search Trees II
Unique Binary Search Trees II Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 uniq原创 2014-01-22 23:08:29 · 954 阅读 · 1 评论 -
LeetCode OJ:Restore IP Addresses
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",原创 2014-01-23 00:20:46 · 1418 阅读 · 0 评论 -
LeetCode OJ:Word Search
Word Search Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizo原创 2014-01-24 21:31:20 · 729 阅读 · 0 评论 -
LeetCode OJ:Search a 2D Matrix
Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to righ原创 2014-01-24 23:18:43 · 825 阅读 · 0 评论 -
LeetCode OJ:Text Justification
Text Justification 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 i原创 2014-01-28 19:28:21 · 1088 阅读 · 0 评论 -
LeetCode OJ:Add Binary
Add Binary Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".class Solution {public: string addBinary(string a, s原创 2014-01-28 20:53:08 · 747 阅读 · 0 评论 -
LeetCode OJ:Spiral Matrix II
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:[ [原创 2014-01-29 00:07:06 · 724 阅读 · 0 评论 -
LeetCode OJ:Pow(x, n)
Pow(x, n) Implement pow(x, n).算法思想:递归TLE,二分法:class Solution {public: double pow(double x, int n) { if(n==0)return 1.0; if(n<0){ if(n==INT_M原创 2014-01-29 13:52:22 · 963 阅读 · 0 评论 -
LeetCode OJ:Anagrams
Anagrams Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.class Solution {public: vector anagrams(vector &s原创 2014-01-29 14:03:47 · 1019 阅读 · 0 评论 -
LeetCode OJ:Multiply Strings
Multiply Strings 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.class So原创 2014-01-29 18:10:30 · 841 阅读 · 0 评论 -
LeetCode OJ:Search Insert Position
Search Insert Position Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may ass原创 2014-01-30 00:07:12 · 715 阅读 · 0 评论 -
LeetCode OJ:Search in Rotated Sorted Array
Search in Rotated Sorted Array 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 value t原创 2014-01-24 15:30:39 · 1091 阅读 · 0 评论 -
LeetCode OJ:Substring with Concatenation of All Words
Substring with Concatenation of All Words You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concate原创 2014-01-30 13:26:33 · 830 阅读 · 0 评论 -
LeetCode OJ:Reverse Nodes in k-Group
Reverse Nodes in k-Group Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes原创 2014-01-30 21:24:54 · 803 阅读 · 0 评论 -
LeetCode OJ:Merge k Sorted Lists
Merge k Sorted Lists Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.算法思想:每次从lists中找一个值最小的加到链中,最小的那个项指向它的下一个节点/** * Definitio原创 2014-01-30 21:49:33 · 739 阅读 · 0 评论 -
LeetCode OJ:3Sum Closest
3Sum Closest 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原创 2014-01-31 00:05:28 · 892 阅读 · 0 评论 -
LeetCode OJ:Integer to Roman
Integer to Roman Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: string intToRoman(int nu原创 2014-01-31 00:50:35 · 825 阅读 · 0 评论 -
LeetCode OJ:Palindrome Number
Palindrome Number 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 a原创 2014-01-31 17:01:04 · 898 阅读 · 0 评论 -
LeetCode OJ:Maximal Rectangle
Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.算法思想:最大子矩阵问题class Solution {public:原创 2014-01-25 00:15:46 · 1514 阅读 · 0 评论 -
LeetCode OJ:Two Sum
Two Sum 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原创 2014-01-31 21:59:22 · 1296 阅读 · 0 评论 -
LeetCode OJ:4Sum
4Sum 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:原创 2014-01-30 23:41:25 · 1023 阅读 · 0 评论 -
LeetCode OJ:Trapping Rain Water
Trapping Rain Water Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Giv原创 2014-01-30 00:05:33 · 1220 阅读 · 0 评论 -
LeetCode OJ:Climbing Stairs
Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?原创 2014-01-28 16:04:37 · 992 阅读 · 0 评论 -
LeetCode OJ:Gas Station
Gas Station Total Accepted: 5589 Total Submissions: 23851My SubmissionsThere are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car wi原创 2014-01-19 23:14:53 · 911 阅读 · 0 评论 -
LeetCode OJ:Candy
Candy 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原创 2014-01-15 17:49:00 · 961 阅读 · 0 评论 -
LeetCode OJ:Single Number
Single Number Total Accepted: 9511 Total Submissions: 21027My SubmissionsGiven an array of integers, every element appears twice except for one. Find that single one.Note:Your algori原创 2014-01-19 22:24:34 · 847 阅读 · 0 评论 -
LeetCode OJ:Single NumberII
Single Number II Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it原创 2014-01-13 14:09:05 · 1042 阅读 · 0 评论 -
LeetCode OJ:LRU Cache
LRU Cache Total Accepted: 3543 Total Submissions: 28382My SubmissionsDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations原创 2014-01-19 21:25:38 · 890 阅读 · 0 评论 -
LeetCode OJ:Longest Valid Parentheses
Longest Valid Parentheses Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest val原创 2014-01-30 00:07:39 · 857 阅读 · 0 评论 -
LeetCode OJ:Largest Rectangle in Histogram
Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.原创 2014-01-25 00:15:12 · 1074 阅读 · 0 评论 -
LeetCode OJ:Evaluate Reverse Polish Notation
Evaluate Reverse Polish Notation Total Accepted: 3892 Total Submissions: 20348My SubmissionsEvaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators ar原创 2014-01-19 20:51:54 · 850 阅读 · 0 评论 -
LeetCode OJ:Binary Tree Inorder Traversal
Binary Tree Inorder Traversal bGiven a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return原创 2014-01-22 23:25:04 · 798 阅读 · 0 评论 -
LeetCode OJ:Binary Tree Level Order Traversal II
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 ex原创 2014-01-22 03:06:51 · 1955 阅读 · 0 评论 -
LeetCode OJ:Insertion Sort List
Insertion Sort List Total Accepted: 4162 Total Submissions: 16278My SubmissionsSort a linked list using insertion sort./** * Definition for singly-linked list. * struct Lis原创 2014-01-19 21:17:41 · 787 阅读 · 0 评论 -
LeetCode OJ:Reorder List
Reorder List Total Accepted: 4205 Total Submissions: 22851My SubmissionsGiven a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place原创 2014-01-19 21:35:48 · 772 阅读 · 0 评论