03 2016 档案

摘要:Given 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 阅读全文
posted @ 2016-03-31 17:18 哥布林工程师 阅读(131) 评论(0) 推荐(0)
摘要:Given an integer array, adjust each integers so that the difference of every adjacent integers are not greater than a given number target. If the arra 阅读全文
posted @ 2016-03-31 13:38 哥布林工程师 阅读(170) 评论(0) 推荐(0)
摘要:Implement a stack with min() function, which will return the smallest number in the stack. It should support push, pop and min operation all in O(1) c 阅读全文
posted @ 2016-03-31 08:51 哥布林工程师 阅读(125) 评论(0) 推荐(0)
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example Given lists: [ 2->4->null, null, -1->null ] 阅读全文
posted @ 2016-03-31 08:43 哥布林工程师 阅读(159) 评论(0) 推荐(0)
摘要:Given an array of integers, find two non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the 阅读全文
posted @ 2016-03-30 13:04 哥布林工程师 阅读(200) 评论(0) 推荐(0)
摘要:Given an array with integers. Find two non-overlapping subarrays A and B, which |SUM(A) - SUM(B)|is the largest. Return the largest difference. Notice 阅读全文
posted @ 2016-03-30 12:52 哥布林工程师 阅读(164) 评论(0) 推荐(0)
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest product. Example For example, given the array [2,3 阅读全文
posted @ 2016-03-30 11:56 哥布林工程师 阅读(179) 评论(0) 推荐(0)
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. Example For example, given the follo 阅读全文
posted @ 2016-03-30 07:32 哥布林工程师 阅读(143) 评论(0) 推荐(0)
摘要:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. Example Given 4 points: (1,2), (3,6), (0,0), (1,3) 阅读全文
posted @ 2016-03-30 06:44 哥布林工程师 阅读(142) 评论(0) 推荐(0)
摘要:Given an array of integers and a number k, the majority number is the number that occurs more than 1/k of the size of the array. Find it. Notice There 阅读全文
posted @ 2016-03-30 02:51 哥布林工程师 阅读(251) 评论(0) 推荐(0)
摘要:Given an array of integers, the majority number is the number that occursmore than 1/3 of the size of the array. Find it. Notice There is only one maj 阅读全文
posted @ 2016-03-29 18:04 哥布林工程师 阅读(121) 评论(0) 推荐(0)
摘要:Given the root and two nodes in a Binary Tree. Find the lowest common ancestor(LCA) of the two nodes. The lowest common ancestor is the node with larg 阅读全文
posted @ 2016-03-29 17:21 哥布林工程师 阅读(180) 评论(0) 推荐(0)
摘要:Given a string, find the length of the longest substring without repeating characters. Example For example, the longest substring without repeating le 阅读全文
posted @ 2016-03-29 17:20 哥布林工程师 阅读(152) 评论(0) 推荐(0)
摘要:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longes 阅读全文
posted @ 2016-03-29 12:47 哥布林工程师 阅读(153) 评论(0) 推荐(0)
摘要:Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return the length of the LIS. Clarification What's the de 阅读全文
posted @ 2016-03-29 12:33 哥布林工程师 阅读(191) 评论(0) 推荐(0)
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Clarification Your algorithm should run in O(n) com 阅读全文
posted @ 2016-03-26 08:25 哥布林工程师 阅读(100) 评论(0) 推荐(0)
摘要:Given two strings, find the longest common substring. Return the length of it. Example Given A = "ABCD", B = "CBCE", return 2. Given A = "ABCD", B = " 阅读全文
posted @ 2016-03-26 06:43 哥布林工程师 阅读(157) 评论(0) 推荐(0)
摘要:Given two strings, find the longest common subsequence (LCS). Your code should return the length of LCS. Example For "ABCD" and "EDCA", the LCS is "A" 阅读全文
posted @ 2016-03-26 03:08 哥布林工程师 阅读(274) 评论(0) 推荐(0)
摘要:Given k strings, find the longest common prefix (LCP). For strings "ABCD", "ABEF" and "ACEF", the LCP is "A" For strings "ABCDEFG", "ABCEFG" and "ABCE 阅读全文
posted @ 2016-03-26 01:57 哥布林工程师 阅读(167) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it. Example Given -21->10->4->5, tail connects to node index 1, return true Given -21->10->4->5, t 阅读全文
posted @ 2016-03-25 08:40 哥布林工程师 阅读(167) 评论(0) 推荐(0)
摘要:Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telepho 阅读全文
posted @ 2016-03-25 08:26 哥布林工程师 阅读(152) 评论(0) 推荐(0)
摘要:Given a list of non negative integers, arrange them such that they form the largest number. Given [1, 20, 23, 4, 8], the largest formed number is 8423 阅读全文
posted @ 2016-03-25 08:05 哥布林工程师 阅读(149) 评论(0) 推荐(0)
摘要:Find the kth smallest number in at row and column sorted matrix. Given k = 4 and a matrix: [ [1 ,5 ,7], [3 ,7 ,8], [4 ,8 ,9], ] return 5 public class 阅读全文
posted @ 2016-03-25 07:35 哥布林工程师 阅读(192) 评论(0) 推荐(0)
摘要:Find K-th largest element in an array. In array [9,3,2,4,8], the 3rd largest element is 4. In array [1,2,3,4,5], the 1st largest element is 5, 2nd lar 阅读全文
posted @ 2016-03-24 13:11 哥布林工程师 阅读(173) 评论(0) 推荐(0)
摘要: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 maxim 阅读全文
posted @ 2016-03-24 12:16 哥布林工程师 阅读(115) 评论(0) 推荐(0)
摘要: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 maxim 阅读全文
posted @ 2016-03-24 11:43 哥布林工程师 阅读(109) 评论(0) 推荐(0)
摘要:Given an integer array (index from 0 to n-1, where n is the size of this array), and an query list. Each query has two integers [start, end]. For each 阅读全文
posted @ 2016-03-24 07:36 哥布林工程师 阅读(184) 评论(0) 推荐(0)
摘要:Given an integer array (index from 0 to n-1, where n is the size of this array), and an query list. Each query has two integers [start, end]. For each 阅读全文
posted @ 2016-03-24 07:23 哥布林工程师 阅读(235) 评论(0) 推荐(0)
摘要:Write a program to find the node at which the intersection of two singly linked lists begins. The following two linked lists: begin to intersect at no 阅读全文
posted @ 2016-03-23 09:01 哥布林工程师 阅读(145) 评论(0) 推荐(0)
摘要:Given three strings: s1, s2, s3, determine whether s3 is formed by the interleaving of s1 and s2. For s1 = "aabcc", s2 = "dbbca" 动态规划,用一个二维数据记录:s1前i个字 阅读全文
posted @ 2016-03-23 08:52 哥布林工程师 阅读(132) 评论(0) 推荐(0)
摘要:Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers. Given [-1, -2, -3, 4, 5, 6], afte 阅读全文
posted @ 2016-03-23 02:35 哥布林工程师 阅读(161) 评论(0) 推荐(0)
摘要:Given an integer, convert it to a roman numeral. The number is guaranteed to be within the range from 1 to 3999. 4 -> IV 12 -> XII 21 -> XXI 99 -> XCI 阅读全文
posted @ 2016-03-22 17:22 哥布林工程师 阅读(126) 评论(0) 推荐(0)
摘要:Implement a trie with insert, search, and startsWith methods. 阅读全文
posted @ 2016-03-22 16:55 哥布林工程师 阅读(164) 评论(0) 推荐(0)
摘要:As the title described, you should only use two stacks to implement a queue's actions. The queue should support push(element), pop()and top() where po 阅读全文
posted @ 2016-03-22 13:21 哥布林工程师 阅读(129) 评论(0) 推荐(0)
摘要: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 @ 2016-03-22 13:16 哥布林工程师 阅读(133) 评论(0) 推荐(0)
摘要:Given an integer array, heapify it into a min-heap array. Given [3,2,1,4,5], return [1,2,3,4,5] or any legal heap array. 阅读全文
posted @ 2016-03-22 13:07 哥布林工程师 阅读(176) 评论(0) 推荐(0)
摘要:The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total num 阅读全文
posted @ 2016-03-22 12:02 哥布林工程师 阅读(141) 评论(0) 推荐(0)
摘要:Given n nodes labeled from 0 to n - 1 and a list ofundirected edges (each edge is a pair of nodes), write a function to check whether these edges make 阅读全文
posted @ 2016-03-22 11:44 哥布林工程师 阅读(159) 评论(0) 推荐(0)
摘要:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Given n = 3, a solution set is: "((()))", "(() 阅读全文
posted @ 2016-03-21 08:21 哥布林工程师 阅读(126) 评论(0) 推荐(0)
摘要:There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it cost 阅读全文
posted @ 2016-03-21 08:09 哥布林工程师 阅读(178) 评论(0) 推荐(0)
摘要:Given an unsorted integer array, find the first missing positive integer. Given [1,2,0] return 3,and [3,4,-1,1] return 2. 思路: 通过在数组进行的交换,把A[i]赋值为i + 1 阅读全文
posted @ 2016-03-21 07:57 哥布林工程师 阅读(149) 评论(0) 推荐(0)
摘要:The code base version is an integer start from 1 to n. One day, someone committed a bad version in the code case, so it caused this version and the fo 阅读全文
posted @ 2016-03-21 07:23 哥布林工程师 阅读(114) 评论(0) 推荐(0)
摘要:Given an array contains N numbers of 0 .. N, find which number doesn't exist in the array. Given N = 3 and the array [0, 1, 3], return 2. 阅读全文
posted @ 2016-03-21 07:20 哥布林工程师 阅读(128) 评论(0) 推荐(0)
摘要:There is an integer array which has the following features: We define a position P is a peek if: Find a peak element in this array. Return the index o 阅读全文
posted @ 2016-03-21 07:16 哥布林工程师 阅读(143) 评论(0) 推荐(0)
摘要: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). Find the minimum element. 阅读全文
posted @ 2016-03-20 14:23 哥布林工程师 阅读(124) 评论(0) 推荐(0)
摘要: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). Find the minimum element. 阅读全文
posted @ 2016-03-20 14:18 哥布林工程师 阅读(149) 评论(0) 推荐(0)
摘要:Calculate the a^n % b where a, b and n are all 32bit integers. For 2^31 % 3 = 2 For 100^1000 % 1000 = 0 这道题有个值得注意的问题,当n为奇数的时候,如果把递归写成: long num = fast 阅读全文
posted @ 2016-03-20 14:11 哥布林工程师 阅读(148) 评论(0) 推荐(0)
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another ex 阅读全文
posted @ 2016-03-20 13:51 哥布林工程师 阅读(129) 评论(0) 推荐(0)
摘要:Given 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 阅读全文
posted @ 2016-03-20 13:44 哥布林工程师 阅读(187) 评论(0) 推荐(0)
摘要:Divide two integers without using multiplication, division and mod operator. If it is overflow, return 2147483647 Given dividend = 100 and divisor = 9 阅读全文
posted @ 2016-03-20 12:56 哥布林工程师 阅读(132) 评论(0) 推荐(0)
摘要:Given 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 t 阅读全文
posted @ 2016-03-20 07:10 哥布林工程师 阅读(169) 评论(0) 推荐(0)
摘要:Count the number of k's between 0 and n. k can be 0 - 9. if n=12, k=1 in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], we have FIVE 1's(1, 10, 11, 12) 阅读全文
posted @ 2016-03-18 13:09 哥布林工程师 阅读(115) 评论(0) 推荐(0)
摘要:Given string A representative a positive integer which has N digits, remove any k digits of the number, the remaining digits are arranged according to 阅读全文
posted @ 2016-03-18 12:56 哥布林工程师 阅读(151) 评论(0) 推荐(0)
摘要:A message containing letters from A-Z is being encoded to numbers using the following mapping: Given an encoded message containing digits, determine t 阅读全文
posted @ 2016-03-18 12:36 哥布林工程师 阅读(155) 评论(0) 推荐(0)
摘要:Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 10000) and an query list. For each query, give you 阅读全文
posted @ 2016-03-18 08:18 哥布林工程师 阅读(176) 评论(0) 推荐(0)
摘要:A 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 阅读全文
posted @ 2016-03-16 13:26 哥布林工程师 阅读(131) 评论(0) 推荐(0)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 阅读全文
posted @ 2016-03-16 13:14 哥布林工程师 阅读(148) 评论(0) 推荐(0)
摘要:Given an integer array, find a continuous subarray where the sum of numbers is the biggest. Your code should return the index of the first number and 阅读全文
posted @ 2016-03-16 12:43 哥布林工程师 阅读(187) 评论(0) 推荐(0)
摘要:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). nvertical lines are drawn such that the two endpoi 阅读全文
posted @ 2016-03-16 12:09 哥布林工程师 阅读(133) 评论(0) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Given in-order [1,2,3] and pre-order [2,1,3], return a tree: 阅读全文
posted @ 2016-03-16 11:57 哥布林工程师 阅读(198) 评论(0) 推荐(0)
摘要:Given inorder and postorder traversal of a tree, construct the binary tree. Given inorder [1,2,3] and postorder [1,3,2], return a tree: 阅读全文
posted @ 2016-03-16 11:41 哥布林工程师 阅读(174) 评论(0) 推荐(0)
摘要:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example,If n = 4 and k = 2, a solution is:[[2,4],[3,4],[ 阅读全文
posted @ 2016-03-16 08:29 哥布林工程师 阅读(146) 评论(0) 推荐(0)
摘要:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in Cwhere the candidate numbers sums to T. Each numb 阅读全文
posted @ 2016-03-16 06:41 哥布林工程师 阅读(183) 评论(0) 推荐(0)
摘要: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 repeat 阅读全文
posted @ 2016-03-16 06:29 哥布林工程师 阅读(170) 评论(0) 推荐(0)
摘要:There are n coins with different value in a line. Two players take turns to take one or two coins from left side until there are no more coins left. T 阅读全文
posted @ 2016-03-16 05:18 哥布林工程师 阅读(182) 评论(0) 推荐(0)
摘要:There are n coins in a line. Two players take turns to take one or two coins from right side until there are no more coins left. The player who take t 阅读全文
posted @ 2016-03-15 13:33 哥布林工程师 阅读(140) 评论(0) 推荐(0)
摘要:Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. 思路: 分为两步 1. BFS,新建所有图中的node,用一个HashMap建立原来node和新的node之 阅读全文
posted @ 2016-03-15 13:20 哥布林工程师 阅读(190) 评论(0) 推荐(0)
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and 阅读全文
posted @ 2016-03-15 12:18 哥布林工程师 阅读(177) 评论(0) 推荐(0)
摘要:Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called 'serialization' and reading back f 阅读全文
posted @ 2016-03-15 11:43 哥布林工程师 阅读(159) 评论(0) 推荐(0)
摘要:Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. Given the below binary tree: return 6.   一个二叉树的最大量 阅读全文
posted @ 2016-03-15 06:29 哥布林工程师 阅读(221) 评论(0) 推荐(0)
摘要:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). Give 阅读全文
posted @ 2016-03-14 17:19 哥布林工程师 阅读(163) 评论(0) 推荐(0)
摘要:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).   Given binary tree {3,9,20,#,#, 阅读全文
posted @ 2016-03-14 17:10 哥布林工程师 阅读(140) 评论(0) 推荐(0)
摘要: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 comple 阅读全文
posted @ 2016-03-14 16:48 哥布林工程师 阅读(191) 评论(0) 推荐(0)
摘要: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 comple 阅读全文
posted @ 2016-03-14 16:37 哥布林工程师 阅读(131) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-03-14 16:31 哥布林工程师 阅读(166) 评论(0) 推荐(0)
摘要:Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the dept 阅读全文
posted @ 2016-03-14 15:05 哥布林工程师 阅读(142) 评论(0) 推荐(0)
摘要:Given n items with size Ai and value Vi, and a backpack with size m. What's the maximum value can you put into the backpack? Given 4 items with size [ 阅读全文
posted @ 2016-03-14 15:00 哥布林工程师 阅读(188) 评论(0) 推荐(0)
摘要:Given n items with size Ai, an integer m denotes the size of a backpack. How full you can fill this backpack? If we have 4 items with size [2, 3, 5, 7 阅读全文
posted @ 2016-03-14 14:48 哥布林工程师 阅读(193) 评论(0) 推荐(0)
摘要:Given an array of strings, return all groups of strings that are anagrams. Given ["lint", "intl", "inlt", "code"], return["lint", "inlt", "intl"]. Giv 阅读全文
posted @ 2016-03-14 14:37 哥布林工程师 阅读(195) 评论(0) 推荐(0)
摘要:Design a data structure that supports the following two operations: addWord(word) and search(word) search(word) can search a literal word or a regular 阅读全文
posted @ 2016-03-14 13:51 哥布林工程师 阅读(185) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2016-03-12 07:27 哥布林工程师 阅读(193) 评论(0) 推荐(0)
摘要: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. 阅读全文
posted @ 2016-03-12 06:49 哥布林工程师 阅读(180) 评论(0) 推荐(0)
摘要: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 z 阅读全文
posted @ 2016-03-12 06:29 哥布林工程师 阅读(212) 评论(0) 推荐(0)
摘要:For a given source string and a target string, you should output the first index(from 0) of target string in source string. If target does not exist i 阅读全文
posted @ 2016-03-11 07:50 哥布林工程师 阅读(125) 评论(0) 推荐(0)
摘要:Determine whether a Sudoku is valid. The Sudoku board could be partially filled, where empty cells are filled with the character .. The following part 阅读全文
posted @ 2016-03-11 06:57 哥布林工程师 阅读(134) 评论(0) 推荐(0)
摘要:Given a string containing just the characters'(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the c 阅读全文
posted @ 2016-03-10 09:23 哥布林工程师 阅读(149) 评论(0) 推荐(0)
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. "A man, a plan, a canal: Panama" is a pa 阅读全文
posted @ 2016-03-10 06:46 哥布林工程师 阅读(147) 评论(0) 推荐(0)
摘要:Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space 阅读全文
posted @ 2016-03-10 06:37 哥布林工程师 阅读(171) 评论(0) 推荐(0)
摘要:A robot is located at the top-left corner of a m x ngrid (marked 'Start' in the diagram below). The robot can only move either down or right at any po 阅读全文
posted @ 2016-03-10 06:25 哥布林工程师 阅读(118) 评论(0) 推荐(0)
摘要:Implement an algorithm to determine if a string has all unique characters. Given "abc", return true. Given "aab", return false. public class Solution 阅读全文
posted @ 2016-03-09 08:44 哥布林工程师 阅读(148) 评论(0) 推荐(0)
摘要:Write a method anagram(s,t) to decide if two strings are anagrams or not. Given s="abcd", t="dcab", return true. public class Solution { /** * @param 阅读全文
posted @ 2016-03-09 08:38 哥布林工程师 阅读(176) 评论(0) 推荐(0)
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. Given the following trian 阅读全文
posted @ 2016-03-09 08:30 哥布林工程师 阅读(169) 评论(0) 推荐(0)
摘要:Write an algorithm which computes the number of trailing zeros in n factorial. 11! = 39916800, so the out should be 2 这道题的思路比较诡异,结尾要有0的话,必须要有质因数2和质因数5 阅读全文
posted @ 2016-03-07 17:43 哥布林工程师 阅读(117) 评论(0) 推荐(0)
摘要:Given a linked list, swap every two adjacent nodes and return its head. Given 1->2->3->4, you should return the list as 2->1->4->3. /** * Definition f 阅读全文
posted @ 2016-03-07 08:44 哥布林工程师 阅读(101) 评论(0) 推荐(0)
摘要:You have two every large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of 阅读全文
posted @ 2016-03-07 08:15 哥布林工程师 阅读(139) 评论(0) 推荐(0)
摘要:Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the l 阅读全文
posted @ 2016-03-07 08:04 哥布林工程师 阅读(130) 评论(0) 推荐(0)
摘要:Implement int sqrt(int x). Compute and return the square root of x. sqrt(3) = 1 sqrt(4) = 2 sqrt(5) = 2 sqrt(10) = 3 mid*mid 以及 (mid + 1) * (mid + 1)都 阅读全文
posted @ 2016-03-07 07:53 哥布林工程师 阅读(115) 评论(0) 推荐(0)
摘要:Write a method to replace all spaces in a string with%20. The string is given in a characters array, you can assume it has enough space for replacemen 阅读全文
posted @ 2016-03-07 07:29 哥布林工程师 阅读(155) 评论(0) 推荐(0)
摘要:Singleton is a most widely used design pattern. If a class has and only has one instance at every moment, we call this design as singleton. For exampl 阅读全文
posted @ 2016-03-07 07:11 哥布林工程师 阅读(140) 评论(0) 推荐(0)
摘要:Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Given [1,2,2,1,3,4,3], return 4 因为所有数都出现了两次,只有一个出现一次,所以只要把所有数做XOR,就可以得到出现一次的数 p 阅读全文
posted @ 2016-03-07 07:05 哥布林工程师 阅读(91) 评论(0) 推荐(0)
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted f 阅读全文
posted @ 2016-03-07 07:03 哥布林工程师 阅读(188) 评论(0) 推荐(0)
摘要: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 or 阅读全文
posted @ 2016-03-07 06:54 哥布林工程师 阅读(181) 评论(0) 推荐(0)
摘要:Given a string and an offset, rotate string by offset. (rotate from left to right) Given "abcdefg". offset=0 => "abcdefg" offset=1 => "gabcdef" offset 阅读全文
posted @ 2016-03-07 06:37 哥布林工程师 阅读(333) 评论(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". Clarification What constitut 阅读全文
posted @ 2016-03-07 06:11 哥布林工程师 阅读(146) 评论(0) 推荐(0)
摘要:Reverse a linked list. For linked list 1->2->3, the reversed linked list is 3->2->1 /** * Definition for ListNode. * public class ListNode { * int val 阅读全文
posted @ 2016-03-06 10:37 哥布林工程师 阅读(159) 评论(0) 推荐(0)
摘要:Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). Given x = 123, return 321 Given x = -123, return  阅读全文
posted @ 2016-03-06 10:16 哥布林工程师 阅读(135) 评论(0) 推荐(0)
摘要:Given a linked list, remove the nth node from the end of list and return its head. Given linked list: 1->2->3->4->5->null, and n = 2. After removing t 阅读全文
posted @ 2016-03-06 10:00 哥布林工程师 阅读(151) 评论(0) 推荐(0)
摘要:Given an array and a value, remove all occurrences of that value in place and return the new length. The order of elements can be changed, and the ele 阅读全文
posted @ 2016-03-06 09:53 哥布林工程师 阅读(167) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2 阅读全文
posted @ 2016-03-06 09:19 哥布林工程师 阅读(126) 评论(0) 推荐(0)
摘要:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For example,Given sorted array A = [1,1,1,2,2,3], Your function should 阅读全文
posted @ 2016-03-06 09:09 哥布林工程师 阅读(121) 评论(0) 推荐(0)
摘要: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 fo 阅读全文
posted @ 2016-03-06 07:47 哥布林工程师 阅读(119) 评论(0) 推荐(0)
摘要:Given a rotated sorted array, recover it to sorted array in-place. [4, 5, 1, 2, 3] -> [1, 2, 3, 4, 5] 方法挺诡异的,记住就好: 找到分界点,把左半边反转,把右半边反转,这时候整个数组就是从大到小排列 阅读全文
posted @ 2016-03-05 07:05 哥布林工程师 阅读(162) 评论(0) 推荐(0)
摘要:Given an integers array A. Define B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], calculate B WITHOUT divide operation. For A = [1, 2, 3], return  阅读全文
posted @ 2016-03-03 13:48 哥布林工程师 阅读(150) 评论(0) 推荐(0)
摘要: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 a 阅读全文
posted @ 2016-03-03 13:31 哥布林工程师 阅读(205) 评论(0) 推荐(0)
摘要:Given a permutation which contains no repeated number, find its index in all the permutations of these numbers, which are ordered in lexicographical o 阅读全文
posted @ 2016-03-03 13:02 哥布林工程师 阅读(138) 评论(0) 推荐(0)
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the 阅读全文
posted @ 2016-03-03 09:27 哥布林工程师 阅读(172) 评论(0) 推荐(0)
摘要:Partition an integers array into odd number first and even number second. Given [1, 2, 3, 4], return [1, 3, 2, 4] public class Solution { /** * @param 阅读全文
posted @ 2016-03-03 08:12 哥布林工程师 阅读(130) 评论(0) 推荐(0)
摘要:Using O(1) time to check whether an integer n is a power of 2. For n=4, return true; For n=5, return false; 这道题就是看一下这个int二进制各位上总共是否只有一个1,如果只有一个1则是2的n次 阅读全文
posted @ 2016-03-03 07:49 哥布林工程师 阅读(120) 评论(0) 推荐(0)
摘要:Given a boolean 2D matrix, find the number of islands. Given graph: [ [1, 1, 0, 0, 0], [0, 1, 0, 0, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 阅读全文
posted @ 2016-03-03 07:44 哥布林工程师 阅读(181) 评论(0) 推荐(0)
摘要:Find the nth to last element of a singly linked list. The minimum number of nodes in list is n. Given a List 3->2->1->5->null and n = 2, return node w 阅读全文
posted @ 2016-03-03 07:24 哥布林工程师 阅读(143) 评论(0) 推荐(0)
摘要:Given an array of integers, find the subarray with smallest sum. Return the sum of the subarray. For [1, -1, -2, 1], return -3 这道题就是把Maximum Subarray反 阅读全文
posted @ 2016-03-03 07:11 哥布林工程师 阅读(132) 评论(0) 推荐(0)
摘要:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. 阅读全文
posted @ 2016-03-03 07:00 哥布林工程师 阅读(181) 评论(0) 推荐(0)
摘要:Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest l 阅读全文
posted @ 2016-03-02 14:20 哥布林工程师 阅读(166) 评论(0) 推荐(0)
摘要:Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted list should be made by splicing together the nodes of the 阅读全文
posted @ 2016-03-02 14:08 哥布林工程师 阅读(163) 评论(0) 推荐(0)
摘要:Merge two given sorted integer array A and B into a new sorted integer array. A=[1,2,3,4] B=[2,4,5,6] return [1,2,2,3,4,4,5,6] 感觉和上一个题没啥区别 class Solut 阅读全文
posted @ 2016-03-02 13:59 哥布林工程师 阅读(163) 评论(0) 推荐(0)
摘要:Given two sorted integer arrays A and B, merge B into A as one sorted array. A = [1, 2, 3, empty, empty], B = [4, 5] After merge, A will be filled as  阅读全文
posted @ 2016-03-02 13:41 哥布林工程师 阅读(181) 评论(0) 推荐(0)
摘要:Given a collection of intervals, merge all overlapping intervals. Given intervals => merged intervals: [ [ [1, 3], [1, 6], [2, 6], => [8, 10], [8, 10] 阅读全文
posted @ 2016-03-02 13:26 哥布林工程师 阅读(234) 评论(0) 推荐(0)
摘要:Given a unsorted array with integers, find the median of it. A median is the middle number of the array after it is sorted. If there are even numbers 阅读全文
posted @ 2016-03-02 13:18 哥布林工程师 阅读(187) 评论(0) 推荐(0)