
leetcode
xin_huang
小小程序猿一枚
展开
-
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.原创 2014-03-29 05:49:10 · 644 阅读 · 0 评论 -
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原创 2014-03-30 04:41:54 · 665 阅读 · 0 评论 -
Linked List Cycle
Given a linked list, determine if it has a cycle in it.Link : 点击打开链接If the fast pointer can catch up the slow pointer again, means there is a cycle.public class Solution { public boolean has原创 2014-03-30 00:51:00 · 433 阅读 · 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原创 2014-03-29 01:23:40 · 448 阅读 · 0 评论 -
Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,public class Solution { public ArrayList> generate(int numRows) { ArrayList> lis原创 2014-03-30 04:14:39 · 602 阅读 · 0 评论 -
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?Solution : recursive , like原创 2014-03-30 00:44:23 · 539 阅读 · 0 评论 -
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-03-29 01:31:34 · 704 阅读 · 0 评论 -
Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.p原创 2014-03-30 04:51:23 · 577 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.public class Solution {原创 2014-03-29 06:01:33 · 484 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.非常直接的一题,运用set来chaja原创 2014-04-24 12:52:35 · 535 阅读 · 0 评论