
面试题
文章平均质量分 61
coobj2008
这个作者很懒,什么都没留下…
展开
-
LeetCode Single Number II
题目要求:Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it原创 2014-03-03 16:38:45 · 396 阅读 · 0 评论 -
LeetCode Single Number
题目及要求:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without原创 2014-03-03 16:31:37 · 348 阅读 · 0 评论 -
LeetCode Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), n原创 2014-03-17 09:48:36 · 269 阅读 · 0 评论 -
LeetCode Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?struct ListNode { int val; ListNod原创 2014-03-17 10:05:14 · 260 阅读 · 0 评论 -
LeetCode Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321class Solution {public: int reverse(int x) { int sign; sign = x > 0 ? 1 : -1; int原创 2014-03-17 10:42:03 · 273 阅读 · 0 评论 -
LeetCode Maximum Depth of Binary Tree
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 leaf node.struct TreeNode { int val; TreeN原创 2014-03-17 10:44:38 · 364 阅读 · 0 评论 -
LeetCode Minimum Depth of Binary Tree
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 leaf node./** * Definition for binary tree原创 2014-03-17 11:24:20 · 290 阅读 · 0 评论 -
2014届华为校园招聘机试题
题目来源:http://blog.youkuaiyun.com/hackbuteer1/article/details/11132567一、题目描述(60分):通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。比如字符串“abacacde”过滤结果为“abcde”。要求实现函数:void stringF原创 2014-03-28 11:23:07 · 365 阅读 · 0 评论 -
LeetCode Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999罗马数字由“IVXLCDM”等组成,分别表示1,5,10,50,100,500,1000。根据规则个位数上的1 2 3 4 5 6 7 8 9的罗马表示为I II I原创 2014-03-17 16:07:24 · 255 阅读 · 0 评论 -
LeetCode Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * Def原创 2014-03-17 10:59:39 · 283 阅读 · 0 评论 -
LeetCode Merge Sorted Array
题目:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional eleme原创 2014-03-17 20:43:15 · 326 阅读 · 0 评论 -
LeetCode Merge Two Sorted Lists
题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * str原创 2014-03-17 22:01:34 · 294 阅读 · 0 评论 -
LeetCode Balanced Binary Tree
题目: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 depth of the two subtrees of every node ne原创 2014-03-17 22:31:50 · 209 阅读 · 0 评论 -
LeetCode Roman to Integer
题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: int romanToInt(string s) { map romap;原创 2014-03-17 19:09:11 · 245 阅读 · 0 评论 -
LeetCode Binary Tree Traversal
1. 非递归的先序遍历Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: R原创 2014-03-17 09:27:37 · 325 阅读 · 0 评论 -
LeetCode Binary Tree Level Order Traversal
题目:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9原创 2014-03-18 14:00:25 · 287 阅读 · 0 评论 -
Best Time to Buy and Sell Stock II
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 complete as many transactions as you like (ie, buy on原创 2014-03-19 10:56:15 · 382 阅读 · 0 评论 -
LeetCode Convert Sorted Array to Binary Search Tree
题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left;原创 2014-03-18 17:14:35 · 249 阅读 · 0 评论 -
LeetCode Combinations
题目: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], [2,3], [1,2], [1,3],原创 2014-04-29 19:31:11 · 261 阅读 · 0 评论 -
LeetCode Pow(x, n)
Implement pow(x, n)./*二分法,复杂度为O(lgn)。注意点:1.n为正数,负数,0;2.INT_MIN的相反数不是INT_MAX*/class Solution {public: double pow(double x, int n) { if (n == 0) return 1.0; if (n < 0) { if (n == INT_MI原创 2014-04-29 20:31:30 · 248 阅读 · 0 评论 -
LeetCode Subsets
题目:Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.原创 2014-04-29 10:40:13 · 277 阅读 · 0 评论 -
LeetCode Best Time to Buy and Sell Stock III
题目: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 complete at most two transactions.Note:原创 2014-03-19 16:58:48 · 318 阅读 · 0 评论 -
LeetCode Symmetric Tree
题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2014-03-18 15:23:20 · 268 阅读 · 0 评论 -
LeetCode Binary Tree Level Order Traversal II
题目: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).For example:Given binary tree {3,9,20,#,原创 2014-03-18 15:50:48 · 266 阅读 · 0 评论 -
LeetCode Unique Binary Search Trees
题目:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2原创 2014-03-18 22:05:10 · 288 阅读 · 0 评论 -
LeetCode Convert Sorted List to Binary Search Tree
题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. * struct ListNode { * int val; *原创 2014-03-18 20:59:03 · 249 阅读 · 0 评论 -
Best Time to Buy and Sell Stock
题目: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 (ie, buy one and sell one share of th原创 2014-03-19 11:06:48 · 394 阅读 · 0 评论 -
LeetCode 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 p原创 2014-03-19 19:02:09 · 346 阅读 · 0 评论 -
LeetCode Remove Duplicates from Sorted Array II
题目: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 return length = 5, and A is no原创 2014-03-19 19:14:54 · 286 阅读 · 0 评论 -
LeetCode Remove Duplicates from Sorted List
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** * Definitio原创 2014-03-19 19:33:46 · 300 阅读 · 0 评论 -
LeetCode Remove Duplicates from Sorted List II
题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Gi原创 2014-03-19 20:49:29 · 314 阅读 · 0 评论 -
LeetCode Pascal's Triangle
题目:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]class Solution {pu原创 2014-03-19 21:28:52 · 268 阅读 · 0 评论 -
LeetCode Unique Paths
题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to r原创 2014-05-01 10:37:48 · 254 阅读 · 0 评论 -
Spiral Matrix II
题目:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9原创 2014-05-02 14:22:03 · 327 阅读 · 0 评论 -
LeetCode Spiral Matrix
题目:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9原创 2014-05-02 14:05:01 · 247 阅读 · 0 评论 -
LeetCode 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?原创 2014-05-02 16:15:19 · 308 阅读 · 0 评论 -
LeetCode Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.原创 2014-05-01 10:14:13 · 232 阅读 · 0 评论 -
LeetCode Unique Paths II
题目: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 is marked as 1 and 0 respectively原创 2014-05-01 11:03:43 · 279 阅读 · 0 评论 -
LeetCode Pascal's Triangle II
题目:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?cla原创 2014-03-20 11:27:27 · 327 阅读 · 0 评论 -
LeetCode Reorder List
题目:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reord原创 2014-03-20 22:32:45 · 224 阅读 · 0 评论