- 博客(69)
- 收藏
- 关注
原创 [Leetcode] #73 Set Matrix Zeroes
Discription: 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 i
2017-02-27 22:18:44 363
原创 [Leetcode] #49 Group Anagrams
Discription: Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return: [ ["ate", "eat","tea"], ["nat","tan"], ["bat"]
2017-02-18 22:03:33 320
原创 [Leetcode] #48 Rotate Image
DiscriptionYou are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Solutionvoid rotate(vector<vector<int>>& matrix) { //顺时针 if (matrix.empty...
2017-02-18 21:32:05 268
原创 [Leetcode] #1#15#18 2Sum & 3Sum & 4Sum
Discription: Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you m
2017-02-18 20:44:27 311
原创 [Leetcode] #17 Letter Combinations of a Phone Number
Discription: 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.
2017-02-18 19:39:06 251
原创 [Leetcode] #215 Kth Largest Element in an Array
Discription:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, retu...
2017-02-18 18:38:57 284
原创 [Leetcode] #415 Add Strings
Discription: Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is Both num1 and num2 contains
2017-02-18 14:07:25 311
原创 [Leetcode] #404 Sum of Left Leaves
Discription: Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respe
2017-02-18 13:36:05 223
原创 [Leetcode] #54 Spiral Matrix
Discription: 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 ],
2017-02-17 21:57:07 303
原创 [Leetcode] #85 Maximal Rectangle
Discription:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix:1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1...
2017-02-17 20:44:41 266
原创 [Leetcode] #84 Largest Rectangle in Histogram
Discription: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.Above is a histogram where width...
2017-02-17 19:59:18 361
原创 [Leetcode] #225 Implement Stack using Queues
Discription:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Ret...
2017-02-17 16:41:25 223
原创 [Leetcode] #232 Implement Queue using Stacks
Discription:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front elemen...
2017-02-17 14:04:39 238
原创 [Leetcode] #257 Binary Tree Paths
Discription:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \ 2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]Solution:vo...
2017-02-17 13:01:30 739
原创 [Leetcode] #226 Invert Binary Tree
Discription: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Solution: TreeNode* invertTree(TreeNode* root) {
2017-02-16 22:15:33 289
原创 [Leetcode] #131#132 Palindrome Partitioning I & II
Discription: Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab", Retur
2017-02-16 21:22:09 289
原创 [Leetcode] #125 Valid Palindrome
Discription: 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. "rac
2017-02-16 18:55:50 248
原创 [Leetcode] #23 Merge k Sorted Lists
Discription:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Solution:class Solution { public: ListNode* merge(ListNode *left, ListNode *right){ Lis...
2017-02-16 17:07:27 233
原创 [Leetcode] #191 Number of 1 Bits
Discription: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary rep
2017-02-16 15:21:57 296
原创 [Leetcode] #26#80 Remove Duplicates from Sorted Array I & II
Discription: 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
2017-02-16 11:49:10 270
原创 [Leetcode] #86 Partition List
Discription: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...
2017-02-16 10:16:55 384
原创 [Leetcode] #75 Sort Colors
Discription: 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, we will
2017-02-15 22:21:15 269
原创 [Leetcode] #67 Add Binary
Discription: Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". Solution: string addBinary(string a, string b) { if (a == ""
2017-02-15 21:25:50 267
原创 [Leetcode] #62#63 Unique Paths I & II
Discription:A robot is located at the top-left corner of amxngrid (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 re...
2017-02-15 20:53:11 260
原创 [Leetcode] #64 Minimum Path Sum
Discription:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or ...
2017-02-15 19:50:27 265
原创 [Leetcode] #43 Multiply Strings
Discription: Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2. Note: The length of both num1 and num2 is Both num1 and num2 cont
2017-02-15 18:54:38 194
原创 [Leetcode] #77 Combinations
Discription: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2],
2017-02-15 16:39:51 202
原创 [Leetcode] #230 Kth Smallest Element in a BST
Discription:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Solution:class Solution...
2017-02-15 16:08:25 214
原创 [Leetcode] #98 Validate Binary Search Tree
Discription: 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
2017-02-15 15:05:13 328
原创 [Leetcode] #46#47 Permutations I & II
DiscriptionGiven a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,...
2017-02-15 14:07:32 293
原创 [Leetcode] #31 Next Permutation
Discription: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 ...
2017-02-15 10:48:36 281
原创 [Leetcode] #78#90 Subsets I & II
Discription:Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3], [1], ...
2017-02-14 21:38:21 278
原创 [Leetcode] #39#40#216 Combination Sum I & II & III
Discription:Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be c...
2017-02-14 21:03:33 425
原创 [Leetcode] #42 Trapping Rain Water
Discription: 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, Given [0,1,0,
2017-02-14 19:48:14 324
原创 [Leetcode] #34 Search for a Range
DiscriptionGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If t...
2017-02-14 18:41:05 298
原创 [Leetcode] #33 Search in Rotated Sorted Array
DiscriptionSuppose an array sorted in ascending order 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 to search. If fou...
2017-02-14 16:48:17 256
原创 [Leetcode] #28 Implement strStr()
Discription: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Solution: int strStr(string haystack, string needle
2017-02-14 15:06:06 239
原创 [Leetcode] #22 Generate Parentheses
DiscriptionGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "(...
2017-02-14 13:04:55 246
原创 [Leetcode] #20 Valid Parentheses
Discription: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()
2017-02-14 12:05:06 198
原创 [Leetcode] #11 Container With Most Water
Discription: 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)
2017-02-14 10:29:52 206
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人