算法
文章平均质量分 57
iCoder_Me
I'm a coder.
展开
-
【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 阅读 · 0 评论 -
【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 阅读 · 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原创 2015-04-06 16:13:33 · 299 阅读 · 0 评论 -
【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 阅读 · 0 评论 -
【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 阅读 · 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),原创 2015-04-05 22:20:19 · 266 阅读 · 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原创 2015-04-05 22:26:44 · 307 阅读 · 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 ma原创 2015-04-05 23:19:30 · 297 阅读 · 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.Accept: 154ms, C++思路原创 2015-04-20 23:35:08 · 383 阅读 · 0 评论 -
【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 阅读 · 0 评论 -
【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】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 阅读 · 0 评论 -
【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 阅读 · 0 评论 -
【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】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 阅读 · 0 评论 -
【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 阅读 · 0 评论 -
【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 阅读 · 0 评论 -
【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 阅读 · 0 评论 -
【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 阅读 · 0 评论 -
【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 阅读 · 0 评论 -
【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 阅读 · 0 评论