自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(29)
  • 收藏
  • 关注

原创 Reverse Words in a String

3rd time begin!!Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarificat

2014-07-01 23:31:49 421

原创 Maximum Subarray

Question: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 subarra

2014-05-21 12:40:55 367

原创 Remove Nth Node From end of List

Question:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node fr

2014-05-19 03:24:22 349

原创 Evaluate Reversed Polish Notation

Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",

2014-04-28 05:36:47 376

原创 LRUCache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if

2014-04-28 04:30:01 427

原创 First Missing Positive

Back to LeetcodeProblem:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should ru

2014-04-23 02:29:31 378

原创 N-queens

Leetcode中的N queens问题是个常见题http://www.cnblogs.com/lichen782/p/leetcode_NQueenII.html搜到的上述博文讲的蛮清楚的只是我渐渐搞不明白了许多需要用DFS,recursive的题目之间的关系subset, permutation, combination,word ladder 等等

2014-03-11 00:30:02 465

原创 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).Tree related problems are very hard to understand for me. So far, this one

2014-02-18 01:38:30 341

原创 sqrt(x)

Sqrt(x) Total Accepted: 7788 Total Submissions: 36159Implement int sqrt(int x).Compute and return the square root of x.Some one suggest using binary search, However a Newton method

2014-02-18 01:33:11 611

原创 permutation I & II

Permutations Total Accepted: 7785 Total Submissions: 25366Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3],

2014-02-15 23:53:24 496

原创 Remove Element

Remove Element Total Accepted: 7901 Total Submissions: 24070Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be

2014-02-12 07:09:59 365

原创 Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y

2014-02-12 07:08:08 422

原创 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.Easy one, if you

2014-02-11 09:45:03 370

原创 Merge K Sorted List

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.1. scan every head of each list, find the minimum value, remove minimum one to the result ListNode

2014-02-11 09:42:21 445

原创 Add Two Number

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link

2014-02-10 10:10:12 436

原创 level- order traversal

BFSfrom: http://leetcode.com/2010/09/printing-binary-tree-in-level-order.htmlpublic void breathFirstTraversalIterative(TreeNode root) { Queue queue = new LinkedList(); TreeNode f

2014-02-10 09:08:06 462

原创 set matrix zeros

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Copied method from:http://www.programcreek.com/2012/12/leetcode-set-matrix-zeroes-java/This pro

2014-02-09 04:07:13 486

原创 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?3 solutionsStill c

2014-02-09 02:29:52 363

原创 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].又是逻辑缺陷所以检查了很久才ac的一道。By using of self-defined c

2014-02-08 00:04:50 550

原创 convert sorted array to binary search tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.要比convert sorted linked list简单/** * Definition for binary tree * public class TreeNode { * i

2014-02-05 12:55:44 386

原创 convert sorted list to binary search tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST思路:已经是sorted list并且按升序排列,那么和in-order traversal的顺序是一致的,所以采用类似in-order的顺序来构建麻烦的点是recursion

2014-02-05 12:52:56 421

原创 Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.目前为止提交次数最少的一次。很简单,都是LinkedList基本操作/** * Definiti

2014-02-05 04:32:03 413

原创 Valid Parentheses

使用stack简单一题做的复杂了public class Solution { public boolean isValid(String s) { Stack st = new Stack(); int i = 0; char bracket = '0'; boolean flag

2014-02-04 10:36:07 341

原创 String to Integer(atoi)

经典题目Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possibl

2014-02-04 09:07:36 392

原创 3 sums

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c

2014-02-04 05:23:10 504

原创 two sum

一道leetcode里的高频面试题题目: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 th

2014-02-04 01:18:41 450

原创 Single number and Single Number IIt

题目分别是:Given an array of integers, every element appears twice except for one. Find that single one.Given an array of integers, every element appears three times except for one. Find that sin

2014-01-29 08:43:59 425

原创 Plus One

今天是个比较简单的题,但还是不能"Accepted"Problem: Given a number represented as an array of digits, plus one to the number有两点,一个是array digits[0]应该存储的是数据的高位另一点是如果array是999,加1会进位,需要新的array长度为digits.length+1找不出

2014-01-29 06:19:26 382

原创 Linked List Merge Sort

开始刷leetcode,进度缓慢...以下我的解答,不过time limit exceeded。要求是in O(n log n) time using constant space complexity.估计是跑two-runner部分太慢了...问了大神,他的解法是bottom-up merge sort,借助了queue的帮助贴自己答案/** * Definition for singly-

2014-01-28 05:41:17 540

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除