- 博客(78)
- 收藏
- 关注
原创 Integer/String Conversions
Integer/String ConversionsWrite two conversion routines. The first routine converts a string to a signed integer. You may assume that the string only contains digits and the minus character (‘-’),
2015-07-15 23:27:19
220
原创 Reverse Words
Reverse WordsWrite a function that reverses the order of the words in a string. For example, your function should transform the string “Do or do not, there is no try.” to “try. no is there not, do o
2015-07-13 08:10:09
249
原创 Reverse Words in a String
Reverse Words in a StringGiven an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programme
2015-07-13 07:57:13
336
原创 Remove Specified Characters
Remove Specified CharactersWrite an efficient function in JAVA that deletes characters from a string. Use the prototype string removeChars( string str, string remove ); where any character existin
2015-07-13 00:36:03
249
原创 Find the First Nonrepeated Character
Find the First Nonrepeated CharacterWrite an efficient function to find the first nonrepeated character in a string. For instance, the first nonrepeated character in “total” is ‘o’ and the first non
2015-07-12 23:44:20
314
原创 Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the
2015-07-12 22:58:05
267
原创 Linked List Cycle I II
Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Keep two kinds of pointers: faster pointe
2015-07-11 22:31:17
183
原创 Copy List With Random Pointer
Copy List with Random PointerA 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 th
2015-07-11 21:52:40
234
原创 Insert Interval
Insert IntervalGiven a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to th
2015-07-09 22:40:35
164
原创 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]./** * Definition for an interval. * public class
2015-07-09 07:55:11
159
原创 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 3 if there is only 3 characters left in the
2015-07-08 23:46:57
297
原创 Largest Rectangle in Histogram
Largest Rectangle in HistogramGiven n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogra
2015-07-08 22:04:37
195
原创 Implement Stack Using LinkedList
import java.io.*;import java.util.*;/* * To execute Java, please define "static void main" on a class * named Solution. * * If you need more classes, simply define them inline. */interface S
2015-07-04 23:42:44
412
原创 Best Time to Buy and Sell Stock III
Best Time to Buy and Sell Stock IIISay 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 co
2015-07-04 12:00:06
265
原创 Scramble String
Scramble StringGiven a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "grea
2015-07-04 11:20:30
408
原创 Kth Smallest Element in a BST
Kth Smallest Element in a BSTGiven a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total e
2015-07-03 02:20:13
239
原创 Recover Binary Search Tree
Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n)
2015-07-02 22:09:17
261
原创 Distinct Subsequences
Distinct SubsequencesGiven a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the origina
2015-07-01 23:23:17
218
原创 Edit Distance
Edit DistanceGiven 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 op
2015-07-01 21:53:40
281
原创 Longest Consecutive Sequence
Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest
2015-07-01 08:08:07
146
原创 N-Queens II
N-Queens IIFollow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.Please refer to the N-queens.public
2015-07-01 02:53:50
160
原创 N-Queens
N-QueensThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions
2015-07-01 02:28:18
178
原创 House Robber II
House Robber IINote: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not ge
2015-06-30 04:30:17
201
原创 House Robber
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 you from robbing each o
2015-06-30 04:10:55
216
原创 summary ranges
Summary RangesGiven a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].Credits:Special thanks to @
2015-06-30 03:56:51
287
原创 Jump Game
Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that
2015-06-21 22:42:38
144
原创 Word Search
Word SearchGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizonta
2015-06-21 22:35:05
208
原创 Maximum Subarray
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 contig
2015-06-21 05:25:26
280
原创 Triangle
TriangleGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[
2015-06-21 05:01:54
184
原创 Minimum Size Subarray Sum
Minimum Size Subarray SumGiven an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 inst
2015-06-21 01:59:41
173
原创 Serialize and Deserialize a binary tree
Serialize and Deserialize a binary treevoid Serialize(TreeNode node) { if (node == null) { System.out.print("#" + " "); return; } System.out.print(node.val + " "); Serialize(nod
2015-06-21 00:47:53
206
原创 Ternary Expression
Ternary Expression a?b:c a / \b ca?b?c:d:e a / \ b e / \c da?b:c?d:e a / \ b c / \ d einput: String exproutput: Expression
2015-06-20 23:48:11
263
原创 Writing a Key Value Store
Writing a Key Value StoreThe purpose of this exercise is to write a basic key value store. It should use string keys and string values only. The following operations should be supported:setget
2015-06-20 05:19:53
277
原创 Missing Ranges
Missing RangesGiven a sorted integer array where the range of elements are [lower, upper] inclusive, return its missing ranges.For example, given [0, 1, 3, 50, 75], lower = 0 and u
2015-06-19 23:25:25
171
原创 Remove Duplicates from Sorted Array I, II
Remove Duplicates from Sorted Array IIFollow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],You
2015-06-19 06:13:13
251
原创 Best Time to Buy and Sell Stock I, II
Best Time to Buy and Sell Stock ISay 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 transacti
2015-06-19 05:34:50
272
原创 Course Schedule II
Course Schedule IIThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first tak
2015-06-19 04:20:06
176
原创 Course Schedule
Course ScheduleThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take c
2015-06-19 03:51:20
200
原创 Basic Calculator
Basic CalculatorImplement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -
2015-06-18 02:26:09
188
原创 implement a queue using stack
//implement a queue using stackpublic class Solution { Stack stack1 = new Stack(); Stack stack2 = new Stack(); //pop: dequeue in stack1 public void dequeue() { if (stack1.peek()
2015-06-17 12:34:48
201
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人