自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

喜欢反对

有多努力就会有多幸运!

  • 博客(108)
  • 收藏
  • 关注

原创 Implement Queue with two Stacks Java

Idea: Implement Queue by using two Stacks: in & outStack in: Insert all value into this StackStack out: reverse order of in stack

2014-09-21 17:48:27 580

原创 Min Stack Java

Question: design a stack which, in addition topush and pop, also has a function min which returns theminimum element? Push, pop and min shouldall operate in O(1) time.

2014-09-21 17:14:22 798

原创 HashMap Implementation Java

Question: Implement the Dat HashMapIdea:    Create a Map class with Key, Value, and Linked list to hanlde collection    HashMap: put operation ->    1. generate the hash value using key with h

2014-09-21 15:27:53 448

原创 Validate Binary Search Tree LeetCode Java

Normal Approach: In_Order Approach    Idea: simply do In_Order traversal, then check    If In_Order traversal of a binary tree is sorted,    then the binary tree is BST. else notpublic static

2014-09-21 10:54:39 491

原创 Binary Tree Level Order Traversal LeetCode Java

Key to solve: BFS by ArrayList    Create a TreeNode list that including all the nodes for each level, terminate loop if list is empty    Build another Integer list that including value of each lev

2014-09-21 09:26:01 375

原创 Palindrome Partitioning II Java

public static int minCut(String s) { if(s==null || s.length()==0) return -1; int len=s.length(); boolean[][] dict=palinDict(s); int[] res=new int[len+1]; res[0]

2014-09-17 14:38:38 409

原创 Palindrome Partitioning Java

Idea: Recursive-loop + dynamic programming + backtracking    Combination of Longest Palindromic Substring & Word Break II    There are two major steps:    1.palindromic dictionary that using sam

2014-09-17 14:15:10 306

原创 Word Break LeetCode Java

Idea: Dynamic programming + Nested Loop    outer loop: i start from 0 to N    inner loop: j start from 0 to i    Use a boolean array in size of N to record the previous info    res[i+1] pu

2014-09-15 17:42:20 436

原创 Word Break II Java

Two Approach: NP-problem    Solution#1: brute force of Recursive-loop, The appraoch is pretty    similar with N-Queens problem    Maintain a result List, traverse all the sub-String list    Ca

2014-09-15 17:40:24 493

原创 Longest Palindromic Substring Java

Idea: Nested loop:    Outer loop: i start from back to front    inner loop: j start from i to the endStated more formally below:Define P[i][j] ← true iffthe substring Si … Sj is a palindrome

2014-09-15 16:22:03 350

原创 Letter Combinations of a Phone Number Java

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.Input:Digit string

2014-09-14 12:38:57 376

原创 N-Queens Java

public class Solution { public static ArrayList solveNQueens(int n) { ArrayList result = new ArrayList(); helperDFS(n,0,new int[n],result); return result;

2014-09-14 08:54:16 458

原创 N-Queens II Java

Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.public class Solution { int res; public int to

2014-09-14 08:51:56 341

原创 Unique Paths II Java

public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { int rows=obstacleGrid.length; int cols=obstacleGrid[0].length; //check for special case

2014-09-13 10:44:22 338

原创 Set Matrix Zeroes Java

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(m

2014-09-04 16:39:11 539

转载 生活需要运气:10招让幸运女神眷顾你!

1. Be Aware of (and Act on) Opportunities认准(并把握住)机会I'm a great believer in luck, and I find the harder I work the more I have of it.  – Thomas Jefferson我很相信运气,我发现我越是努力,就越发幸运。 ——托马斯·杰斐逊How much

2014-09-03 07:55:52 660

原创 Lowest Common Ancestor of a Binary Tree Part I

Given a binary tree, find the lowest common ancestor of two given nodes in the tree. _______3______ / \ ___5__ ___1__ / \ / \

2014-08-29 17:47:01 434

原创 Lowest Common Ancestor of a Binary Search Tree

Given a binary search tree (BST), find the lowest common ancestor of two given nodes in the BST. _______6______ / \ ___2__ ___8__ / \

2014-08-29 17:39:05 283

原创 Subsets II Java

Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain dupli

2014-08-29 11:32:04 388

原创 Subsets Java

Solution: Non-Recursion method    NP-Problem again.    The Number of Subsets is 2(N+1)    Idea: Create result list from Nothing to something that means    generate from empty set to some eleme

2014-08-29 11:30:30 365

原创 Rotate Image Java

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?Have you been asked this question in an i

2014-08-29 11:14:56 428

原创 Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?

2014-08-29 10:42:23 281

原创 Pascal's Triangle Java

Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Have you

2014-08-29 10:40:21 327

原创 Generate Parentheses Java

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()

2014-08-29 10:30:24 568

转载 Android Interview question

Ref:http://androidjayavelu.blogspot.com/p/android-interview-question.htmlAndroid Interview questionWhat is Android ?It is an open_sourced operating system that is used primaril

2014-08-29 09:55:09 1511

原创 Restore IP Addresses Java

Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order

2014-08-28 09:30:22 354

原创 Plus One Java

Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.Have y

2014-08-28 08:57:26 391

原创 Unique Binary Search Trees II Java

Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3

2014-08-27 16:30:11 502

原创 Unique Binary Search Trees Java

Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \

2014-08-27 13:26:45 416

原创 Best Time to Buy and Sell Stock III Java

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 may no

2014-08-27 10:57:19 378

原创 Best Time to Buy and Sell Stock II Java

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-08-27 10:38:55 307

原创 Best Time to Buy and Sell Stock Java

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),

2014-08-27 10:19:20 326

原创 Reverse Words in a String Java

Idea: the regular approach is to us split method in Java    that split each word by space " ", then reverse each word from back to front.    Watch out for the special cases.    remember to elimi

2014-08-26 09:54:21 433

原创 Combination Sum II Java

Idea: 99% same as Combination Sum, beside, the duplication is not     allow, all we need to do is to increment last selection by i+1 instead i     before in Combination Sum & skip the recursion st

2014-08-25 16:55:36 448

原创 Combination Sum Java

Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb

2014-08-25 16:35:26 426

原创 Combinations Java

Idea: same idea as Permutations that    use Loop Recursion to handle sub problem to obtain a list of    Combinations.    n: selection range [1...n]    k: number of selection required    la

2014-08-25 16:32:45 471

原创 Permutations II Java

Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1

2014-08-25 16:20:09 487

原创 Permutations Java

Given a collection of 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], and [3,2,1].Two Approac

2014-08-25 04:14:14 959

原创 Implement strStr() Java

Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack. Goal: Determine whether needle is substring of haystack or not &

2014-08-24 15:21:06 461

原创 Length of Last Word Java

Goal: find Length of Last Word    the length will depend on the index of last Character - last index of  spacepublic class Solution { public int lengthOfLastWord(String s) { if(s.leng

2014-08-22 17:05:08 309

空空如也

空空如也

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

TA关注的人

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