2015年5月9日

Majority Number III

摘要: Given an array of integers and a number k, the majority number is the number that occursmore than 1/kof the size of the array.Find it.ExampleGiven[3,1... 阅读全文

posted @ 2015-05-09 07:25 Step-BY-Step 阅读(265) 评论(0) 推荐(0) 编辑

2015年5月8日

Implement Trie (Prefix Tree)

摘要: Implement a trie withinsert,search, andstartsWithmethods.Note:You may assume that all inputs are consist of lowercase lettersa-z.由于用的是 26位字母的array, 所以... 阅读全文

posted @ 2015-05-08 12:44 Step-BY-Step 阅读(207) 评论(0) 推荐(0) 编辑

2015年5月7日

Reverse Linked List

摘要: Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?I... 阅读全文

posted @ 2015-05-07 12:13 Step-BY-Step 阅读(267) 评论(0) 推荐(0) 编辑

Course Schedule

摘要: There are a total ofncourses you have to take, labeled from0ton - 1.Some courses may have prerequisites, for example to take course 0 you have to firs... 阅读全文

posted @ 2015-05-07 11:55 Step-BY-Step 阅读(197) 评论(0) 推荐(0) 编辑

2015年4月29日

Number of Islands

摘要: Given a 2d grid map of'1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent ... 阅读全文

posted @ 2015-04-29 10:57 Step-BY-Step 阅读(180) 评论(0) 推荐(0) 编辑

Bitwise AND of Numbers Range

摘要: Given a range [m, n] where 0 = 0 && (((m >> i) & 1) == ((n >> i) & 1)); i --){5 result |= (((m >> i) & 1) << i);6 }7 retur... 阅读全文

posted @ 2015-04-29 10:39 Step-BY-Step 阅读(145) 评论(0) 推荐(0) 编辑

Happy Number

摘要: Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer... 阅读全文

posted @ 2015-04-29 10:06 Step-BY-Step 阅读(160) 评论(0) 推荐(0) 编辑

Remove Linked List Elements

摘要: Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --... 阅读全文

posted @ 2015-04-29 10:05 Step-BY-Step 阅读(133) 评论(0) 推荐(0) 编辑

Count Primes

摘要: Description:Count the number of prime numbers less than a non-negative number,n 1 public class Solution { 2 public int countPrimes(int n) { 3 ... 阅读全文

posted @ 2015-04-29 10:04 Step-BY-Step 阅读(315) 评论(0) 推荐(0) 编辑

Isomorphic Strings

摘要: Given two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrences of a ... 阅读全文

posted @ 2015-04-29 09:59 Step-BY-Step 阅读(120) 评论(0) 推荐(0) 编辑

2015年4月17日

Read N Characters Given Read4 II - Call multiple times

摘要: The API:int read4(char *buf)reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns... 阅读全文

posted @ 2015-04-17 07:11 Step-BY-Step 阅读(175) 评论(0) 推荐(0) 编辑

2015年4月8日

Word Ladder II Graph

摘要: Given two words (startandend), and a dictionary, find all shortest transformation sequence(s) fromstarttoend, such that:Only one letter can be changed... 阅读全文

posted @ 2015-04-08 11:45 Step-BY-Step 阅读(447) 评论(0) 推荐(0) 编辑

2015年4月6日

Word Ladder

摘要: Given two words (startandend), and a dictionary, find all transformation sequence(s) fromstarttoend, such that:Only one letter can be changed at a tim... 阅读全文

posted @ 2015-04-06 09:49 Step-BY-Step 阅读(258) 评论(0) 推荐(0) 编辑

Binary Tree Right Side View

摘要: Given a binary tree, imagine yourself standing on therightside of it, return the values of the nodes you can see ordered from top to bottom.For exampl... 阅读全文

posted @ 2015-04-06 06:05 Step-BY-Step 阅读(270) 评论(0) 推荐(0) 编辑

House Robber

摘要: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo... 阅读全文

posted @ 2015-04-06 05:55 Step-BY-Step 阅读(147) 评论(0) 推荐(0) 编辑

2015年4月3日

Find non-overlap jobs with max cost

摘要: Given a set of n jobs with [start time, end time, cost] find a subset so that no 2 jobs overlap and the cost is maximum.Job: (start_time, end_time] ... 阅读全文

posted @ 2015-04-03 15:15 Step-BY-Step 阅读(301) 评论(0) 推荐(0) 编辑

2015年3月30日

Find Peak Element

摘要: A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index.... 阅读全文

posted @ 2015-03-30 15:21 Step-BY-Step 阅读(153) 评论(0) 推荐(0) 编辑

Implement Trie and find longest prefix string list

摘要: 1 package leetcode; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 class TrieNode{ 7 Boolean isWord;//true if path till ... 阅读全文

posted @ 2015-03-30 07:37 Step-BY-Step 阅读(151) 评论(0) 推荐(0) 编辑

2015年3月27日

第501篇随笔

摘要: 突然发现自己从前年到现在刚好两年的时间里,已经写了500篇随笔。虽然有一部分是从网上down下来的,不过很多都还是自己的code。纪念一下。。。 阅读全文

posted @ 2015-03-27 11:08 Step-BY-Step 阅读(119) 评论(0) 推荐(0) 编辑

implement min heap

摘要: 1 class MinHeap{ 2 private ArrayList arr; 3 private int DEFAULT_LEN = 10; 4 public MinHeap(){ 5 arr = new ArrayList(DEFAULT_LEN);... 阅读全文

posted @ 2015-03-27 11:01 Step-BY-Step 阅读(249) 评论(0) 推荐(0) 编辑

find K maximum value from an unsorted array(implement min heap)

摘要: Maintain a min-heap with size = k, to collect the result. 1 //Find K minimum values from an unsorted array 2 //Implement Min-Heap 3 4 public int[] fi... 阅读全文

posted @ 2015-03-27 09:50 Step-BY-Step 阅读(254) 评论(0) 推荐(0) 编辑

2015年3月26日

Rotate Array II

摘要: Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come... 阅读全文

posted @ 2015-03-26 11:58 Step-BY-Step 阅读(177) 评论(0) 推荐(0) 编辑

Reverse Bits

摘要: Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as00000010100101000001111010011100), return ... 阅读全文

posted @ 2015-03-26 11:13 Step-BY-Step 阅读(133) 评论(0) 推荐(0) 编辑

override toString() function for TreeNode to output OJ's Binary Tree Serialization

摘要: 1 class TreeNode { 2 int val; 3 TreeNode left; 4 TreeNode right; 5 TreeNode(int x) { val = x; } 6 7 @Override 8... 阅读全文

posted @ 2015-03-26 10:38 Step-BY-Step 阅读(330) 评论(0) 推荐(0) 编辑

Construct BST from given preorder traversal

摘要: Given preorder traversal of a binary search tree, construct the BST.For example, if the given traversal is {10, 5, 1, 7, 40, 50}, then the output shou... 阅读全文

posted @ 2015-03-26 10:34 Step-BY-Step 阅读(282) 评论(0) 推荐(0) 编辑

autoboxing and unboxing

摘要: Why does 128==128 return false but 127==127 return true 1 public static void autoboxingUnboxing(){ 2 Integer ta = 127; 3 Integer tb =... 阅读全文

posted @ 2015-03-26 00:24 Step-BY-Step 阅读(195) 评论(0) 推荐(0) 编辑

2015年3月25日

Number of 1 Bits

摘要: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit in... 阅读全文

posted @ 2015-03-25 16:01 Step-BY-Step 阅读(153) 评论(0) 推荐(0) 编辑

Best Time to Buy and Sell Stock IV

摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文

posted @ 2015-03-25 14:42 Step-BY-Step 阅读(243) 评论(0) 推荐(0) 编辑

2015年3月22日

multi thread for Java

摘要: I try to do a testing for HashTable Sychronized behavior today.As an Sychronized Object, HashTable already an Sychronized at put and get function. I w... 阅读全文

posted @ 2015-03-22 04:59 Step-BY-Step 阅读(574) 评论(0) 推荐(0) 编辑

2015年3月15日

Print Nodes in Top View of Binary Tree

摘要: Top view of a binary tree is the set of nodes visible when the tree is viewed from the top. Given a binary tree, print the top view of it. The output ... 阅读全文

posted @ 2015-03-15 01:42 Step-BY-Step 阅读(297) 评论(0) 推荐(0) 编辑

Print a Binary Tree in Vertical Order

摘要: Given a binary tree, print it vertically. The following example illustrates vertical order traversal. 1 / \ 2 3 / ... 阅读全文

posted @ 2015-03-15 01:08 Step-BY-Step 阅读(167) 评论(0) 推荐(0) 编辑

2015年3月12日

Binary Search Tree Iterator

摘要: Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next... 阅读全文

posted @ 2015-03-12 15:58 Step-BY-Step 阅读(319) 评论(0) 推荐(0) 编辑

2015年2月23日

Minimum Adjustment Cost

摘要: Given an integer array, adjust each integers so that the difference of every adjcent integers are not greater than a given number target.If the array ... 阅读全文

posted @ 2015-02-23 14:07 Step-BY-Step 阅读(252) 评论(0) 推荐(0) 编辑

2015年2月6日

Reverse Words in a String II

摘要: Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.The input string does not contain lead... 阅读全文

posted @ 2015-02-06 15:57 Step-BY-Step 阅读(291) 评论(0) 推荐(0) 编辑

Repeated DNA Sequences

摘要: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to ... 阅读全文

posted @ 2015-02-06 15:41 Step-BY-Step 阅读(407) 评论(0) 推荐(0) 编辑

2015年1月25日

Longest Substring with At Most Two Distinct

摘要: Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s =“eceba”,T is "ece" which ... 阅读全文

posted @ 2015-01-25 03:27 Step-BY-Step 阅读(193) 评论(0) 推荐(0) 编辑

2015年1月19日

Two Sum III - Data structure design

摘要: Design and implement a TwoSum class. It should support the following operations:addandfind.add- Add the number to an internal data structure.find- Fin... 阅读全文

posted @ 2015-01-19 15:22 Step-BY-Step 阅读(549) 评论(0) 推荐(0) 编辑

Two Sum II - Input array is sorted

摘要: Given an array of integers that is alreadysorted in ascending order, find two numbers such that they add up to a specific target number.The function t... 阅读全文

posted @ 2015-01-19 14:51 Step-BY-Step 阅读(194) 评论(0) 推荐(0) 编辑

Read N Characters Given Read4

摘要: The API:int read4(char *buf)reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns... 阅读全文

posted @ 2015-01-19 14:40 Step-BY-Step 阅读(218) 评论(0) 推荐(0) 编辑

Binary Tree Upside Down

摘要: Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it up... 阅读全文

posted @ 2015-01-19 14:26 Step-BY-Step 阅读(210) 评论(0) 推荐(0) 编辑

导航