- 博客(200)
- 资源 (1)
- 收藏
- 关注
原创 CODE 120: Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin
2013-11-10 15:54:04 482
原创 CODE 119: Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999. static List r2a = new ArrayList(); static { r2a.add(new R2A(1000, 'M')); r2a.
2013-11-10 14:19:44 530
原创 CODE 118: Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. static Map r2a = new HashMap(); static { r2a.put('I', 1); r2a.put('V', 5);
2013-11-10 12:19:02 732
原创 CODE 117: Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. public String longestCommonPrefix(String[] strs) { // Start typing your Java solution below // DO NOT wri
2013-11-09 22:28:32 656
原创 CODE 114: 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements
2013-11-09 21:15:05 699
原创 CODE 115: 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact
2013-11-08 22:32:29 445
原创 CODE 116: 3Sum
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)
2013-11-08 21:23:19 464
原创 CODE 113: Letter Combinations of a Phone Number
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
2013-11-06 21:49:32 552
原创 CODE 112: Remove Nth Node From End of List
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 from the end, the
2013-11-06 20:23:28 532
原创 CODE 111: Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va
2013-11-06 19:51:53 626
原创 CODE 110: Generate Parentheses
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:"((()))", "(()())", "(())()", "()(())", "()()
2013-11-05 21:26:28 588
原创 CODE 109: Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. public ListNode mergeKLists(ArrayList lists) { // IMPORTANT: Please reset any member data you
2013-11-05 19:48:01 466
原创 CODE 108: 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
2013-11-04 20:32:03 570
原创 CODE 107: Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is
2013-11-04 20:19:47 657
原创 CODE 106: Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with
2013-11-04 19:43:49 587
原创 CODE 105: Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length. pu
2013-11-03 18:59:17 512
原创 CODE 104: Divide Two Integers
Divide two integers without using multiplication, division and mod operator. public int divide(int dividend, int divisor) { // IMPORTANT: Please reset any member data you declared, as // the s
2013-11-03 16:35:51 555
原创 CODE 103: Substring with Concatenation of All Words
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 concatenation of each word in L exactly once and without an
2013-11-03 14:28:21 566
原创 CODE 102: Next Permutation
public void nextPermutation(int[] num) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. List rest = new ArrayList();
2013-11-01 23:10:05 515
原创 CODE 101: Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", wh
2013-11-01 22:28:45 413
原创 CODE 100: Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur
2013-10-31 22:25:17 476
原创 CODE 99: Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found
2013-10-31 21:57:07 677
原创 CODE 98: Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.
2013-10-30 22:59:11 435
原创 CODE 97: Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille
2013-10-30 22:32:20 663
原创 CODE 96: Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku
2013-10-29 22:05:06 514
原创 CODE 95: Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "o
2013-10-29 20:47:45 531
原创 CODE 93: Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina
2013-10-28 21:30:20 497
原创 CODE 94: Combination Sum
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
2013-10-28 21:11:00 556
原创 CODE 92: First Missing Positive
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 run in O(n) time and uses constant
2013-10-28 19:25:31 563
原创 CODE 91: Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]
2013-10-27 22:20:33 530
原创 CODE 90: Multiply Strings
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. public String multiply(String num1
2013-10-27 19:38:08 546
转载 无题
点击打开链接------------------------------------------------------------------------------------ 后面是9月份以前默默的自己瞎写的内容,那时候还不知道找工作会遇到什么,哎呀,不舍得删 ------------------------------------------------------
2013-10-27 16:15:38 853
原创 CODE 89: Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t
2013-10-27 11:03:54 590
原创 CODE 88: Jump Game II
Given 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 position.Your goal i
2013-10-20 21:46:52 623
原创 CODE 86: Permutations II
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].
2013-10-20 15:43:32 548
原创 CODE 87: Permutations
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]. public Arr
2013-10-20 15:29:24 456
原创 CODE 85: Rotate Image
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? public void rotate(int[][] matrix) { // Start
2013-10-19 00:28:46 544
原创 CODE 84: Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case. public ArrayList anagrams(String[] strs) { // Note: The Solution object is
2013-10-18 21:52:12 505
转载 转一篇有关JAVA的内存泄露的文章
http://www.lybbs.net/news_read.do?newsPath=2007/9/25/1190684628458.html 1 引言 Java的一个重要优点就是通过垃圾收集器GC (Garbage Collection)自动管理内存的回收,程序员不需要通过调用函数来释放内存。因此,很多程序员认为Java 不存在内存泄漏问题,或者认为即使有内存泄漏也不是程
2013-10-17 19:27:14 529
原创 CODE 83: Pow(x, n)
Implement pow(x, n). public double pow(double x, int n) { // Note: The Solution object is instantiated only once and is reused by // each test case. boolean minus = false; double result =
2013-10-16 23:17:57 758
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人