02 2016 档案
摘要:Given an array of integers, find a contiguous subarray which has the largest sum. Given the array [−2,2,−3,4,−1,2,1,−5,3], the contiguous subarray[4,−
阅读全文
摘要:Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest l
阅读全文
摘要:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ZigZag-order. Given a matrix: [ [1, 2, 3, 4], [5, 6, 7, 8],
阅读全文
摘要:Given an array of integers, the majority number is the number that occurs more than half of the size of the array. Find it. Example Given [1, 1, 1, 1,
阅读全文
摘要:Given a dictionary, find all of the longest words in the dictionary. Example Given { "dog", "google", "facebook", "internationalization", "blabla" } t
阅读全文
摘要:Give an integer array,find the longest increasing continuous subsequence in this array. An increasing continuous subsequence: Can be from right to lef
阅读全文
摘要:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word
阅读全文
摘要:Invert a binary tree. Example 1 1 / \ / \ 2 3 => 3 2 / \ 4 4 Challenge Do it in recursion is acceptable, can you do it without recursion? 1. 递归 /** *
阅读全文
摘要:Sort a linked list using insertion sort. Example Given 1->3->2->0->null, return 0->1->2->3->null. 思路也比较直接,insertion sort,要注意的就是操作linkedlist的一些问题 /** *
阅读全文
摘要:Given a binary search tree and a new tree node, insert the node into the tree. You should keep the tree still be a valid binary search tree. Example G
阅读全文
摘要:Given a non-overlapping interval list which is sorted by start point. Insert a new interval into it, make sure the list is still in order and non-over
阅读全文
摘要:Check if two binary trees are identical. Identical means the two binary trees have the same structure and every identical position has the same value.
阅读全文
摘要:In data structure Hash, hash function is used to convert a string(or any other type) into an integer smaller than hash size and bigger or equal to zer
阅读全文
摘要: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,
阅读全文
摘要:Determine the number of bits required to flip if you want to convert integer n to integer m. Example Given n = 31 (11111), m = 14 (01110), return 2. N
阅读全文
摘要:Flatten a binary tree to a fake "linked list" in pre-order traversal. Here we use the right pointer in TreeNode as the nextpointer in ListNode. Exampl
阅读全文
摘要:For a given sorted array (ascending order) and atarget number, find the first index of this number inO(log n) time complexity. If the target number do
阅读全文
摘要:Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node. Example Given 1->2->3->4, and node 3. r
阅读全文
摘要: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 o
阅读全文
摘要:Count how many 1 in binary representation of a 32-bit integer. Example Given 32, return 1 Given 5, return 2 Given 1023, return 9 Challenge If the inte
阅读全文
摘要:Cosine similarity is a measure of similarity between two vectors of an inner product space that measures the cosine of the angle between them. The cos
阅读全文
摘要:Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height. Example Given [1,2,3,4,5,6,7], return 4 / \ 2 6 / \ /
阅读全文
摘要:Compare two strings A and B, determine whether A contains all of the characters in B. The characters in string A and B are all Upper Case letters. Exa
阅读全文
摘要:You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you cl
阅读全文
摘要:Given a binary tree, return the preorder traversal of its nodes' values. Example Given: 1 / \ 2 3 / \ 4 5 return [1,2,4,5,3]. Challenge Can you do it
阅读全文
摘要:Given a binary tree, return the postorder traversal of its nodes' values. Example Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. Challenge Can
阅读全文
摘要:Given a binary tree, return all root-to-leaf paths. 这道题主要利用一下java的一个特性,String是immutable的对象,不能修改,只能重新生成 /** * Definition of TreeNode: * public class Tr
阅读全文
摘要:Given a binary tree, return the inorder traversal of its nodes' values. Example Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2]. Challenge Can y
阅读全文
摘要:You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's
阅读全文
摘要:Given two binary strings, return their sum (also a binary string). Example a = 11 b = 1 Return 100 这道题也没太多好说的…… public class Solution { /** * @param a
阅读全文
摘要:Write a function that add two numbers A and B. You should not use + or any arithmetic operators. Example Given a=1 and b=2 return 3 Note There is no n
阅读全文
摘要:Remove all elements from a linked list of integers that have value val. Example Given 1->2->3->3->4->5->3, val = 3, you should return the list as1->2-
阅读全文
摘要:Find the Nth number in Fibonacci sequence. A Fibonacci sequence is defined as follow: The first two numbers are 0 and 1. The i th number is the sum of
阅读全文

浙公网安备 33010602011771号