- 博客(21)
- 收藏
- 关注
原创 【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.Accept: 154ms, C++思路
2015-04-20 23:35:08 383
原创 【leetcode】Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Accept: 22ms思路:中根遍历+后根遍历还原一棵二叉树。to
2015-04-17 22:44:58 408
原创 【leetcode】Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you consider the case where path
2015-04-14 22:13:49 323
原创 【leetcode】Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Accept: 2mschar *addBinary(char *a, char *b) { int len_a = (int)strlen(a
2015-04-13 21:47:49 288
原创 【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
2015-04-06 16:13:33 299
原创 【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 ma
2015-04-05 23:19:30 297
原创 【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
2015-04-05 22:26:44 307
原创 【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),
2015-04-05 22:20:19 266
原创 【leetcode】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 the target, whe
2015-04-05 22:06:26 290
原创 【leetcode】Valid Parentheses
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 va
2015-04-05 22:05:50 246
原创 【leetcode】Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.O(N * logK)/** * Definition for singly-linked list. * struct ListNode { * int val; *
2015-04-05 22:03:36 256
原创 【leetcode】Find Minimum 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).Find the minimum element.You may assume no duplicate exists in
2015-04-05 22:00:52 325 1
原创 【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.O(N^2), Accept
2015-04-05 21:58:40 301
原创 【leetcode】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?Accept: 1msint dp[
2015-04-05 21:50:44 263
原创 【leetcode】Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].Accept: 20ms#include bool cmp(const Interv
2015-04-05 21:49:25 216
原创 【leetcode】Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:
2015-04-05 21:47:22 361 2
原创 【leetcode】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 valid parentheses substring is "()",
2015-04-05 21:45:12 294
原创 【leetcode】Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha
2015-04-05 21:41:57 205
原创 【leetcode】Unique Paths II
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 the
2015-04-05 21:37:15 268
原创 【leetcode】Unique Paths
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 t
2015-04-05 21:34:17 290
原创 【leetcode】Minimum Path Sum
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 right at any
2015-04-05 21:31:33 361
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人