摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
posted @ 2014-06-04 12:41 Averill Zheng 阅读(107) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu... 阅读全文
posted @ 2014-06-04 12:11 Averill Zheng 阅读(96) 评论(0) 推荐(0) 编辑
摘要: Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest... 阅读全文
posted @ 2014-06-04 11:13 Averill Zheng 阅读(124) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which rep... 阅读全文
posted @ 2014-06-04 05:55 Averill Zheng 阅读(120) 评论(0) 推荐(0) 编辑
摘要: Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.public class Solution { /** * This program is used t... 阅读全文
posted @ 2014-06-03 06:38 Averill Zheng 阅读(159) 评论(0) 推荐(0) 编辑
摘要: You are given a string,S, and a list of words,L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenati... 阅读全文
posted @ 2014-05-28 11:32 Averill Zheng 阅读(113) 评论(0) 推荐(0) 编辑
摘要: Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.2... 阅读全文
posted @ 2014-03-22 06:43 Averill Zheng 阅读(166) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie,a≤b≤c≤d)The solution set must not contain duplicate quadruplets. . 阅读全文
posted @ 2014-03-22 02:10 Averill Zheng 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elemen... 阅读全文
posted @ 2014-03-22 01:11 Averill Zheng 阅读(147) 评论(0) 推荐(0) 编辑
摘要: Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"click to show corner cases.Corner Cases:Did you consider the case wherepath="/../"?In this case, you should return&quo 阅读全文
posted @ 2014-03-20 05:54 Averill Zheng 阅读(155) 评论(0) 推荐(0) 编辑
摘要: Given an array of words and a lengthL, format the text such that each line has exactlyLcharacters and is fully (left and right) justified.You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces' 'when necessary so that each line 阅读全文
posted @ 2014-03-20 04:06 Averill Zheng 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.Have you been asked this question in an interview?public class Solution { public String multiply(String num1, String num2) { int len1 =... 阅读全文
posted @ 2014-03-19 23:58 Averill Zheng 阅读(131) 评论(0) 推荐(0) 编辑
摘要: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number ... 阅读全文
posted @ 2014-03-19 15:09 Averill Zheng 阅读(169) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histog... 阅读全文
posted @ 2014-03-19 06:38 Averill Zheng 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 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.public class Solution { public String reverseWords(String s) { StringBuffer reverse = new StringBuffer(); int len = s.length(); if(l 阅读全文
posted @ 2014-03-10 11:53 Averill Zheng 阅读(304) 评论(0) 推荐(0) 编辑
摘要: Divide two integers without using multiplication, division and mod operator.Have you been asked this question in an interview?YesDiscusspublic class Solution { public int divide(int dividend, int divisor) { int sign = (dividend = absDivs){ temp 0){ result = ab... 阅读全文
posted @ 2014-03-03 07:42 Averill Zheng 阅读(124) 评论(0) 推荐(0) 编辑
摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the value if the key is not 阅读全文
posted @ 2014-03-03 03:13 Averill Zheng 阅读(319) 评论(0) 推荐(0) 编辑
摘要: Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Retun all such possible... 阅读全文
posted @ 2014-02-28 04:09 Averill Zheng 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 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 ... 阅读全文
posted @ 2014-02-27 12:11 Averill Zheng 阅读(129) 评论(0) 推荐(0) 编辑
摘要: Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl... 阅读全文
posted @ 2014-02-27 12:00 Averill Zheng 阅读(137) 评论(0) 推荐(0) 编辑