面试
文章平均质量分 56
浣熊
北京邮电大学计算机学院 嵌入式系统与网络通信实验室 iOS/Android应用开发
展开
-
面试编程——atoi实现
//// main.cpp// my_atoi//// Created by on 14-5-6.// Copyright (c) 2014年 yuanbo. All rights reserved.///* 基础需求: (1)‘+’、‘-’号 (2)开头空格 (3)合法性判断 (4)溢出判断 高级需求(未实现): (1)逗号,如1,234,567 (原创 2014-05-06 09:16:01 · 986 阅读 · 0 评论 -
[LeetCode] Search a 2D Matrix
题目: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 from left to right.The first intege原创 2014-06-10 18:30:39 · 671 阅读 · 0 评论 -
[LeetCode] Binary Tree Postorder Traversal [递归版]
题目:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recurs原创 2014-06-10 15:54:03 · 594 阅读 · 0 评论 -
[LeetCode] 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].解答:原创 2014-06-10 14:43:13 · 627 阅读 · 0 评论 -
[LeetCode] Plus One
题目: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 at the head of the list.解答原创 2014-06-08 16:41:39 · 1524 阅读 · 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?解答:class Solution {public: void rotat原创 2014-06-08 15:30:43 · 650 阅读 · 0 评论 -
[LeetCode] Climbing Stairs
tiYou 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 climb to the top?原创 2014-05-24 10:12:35 · 716 阅读 · 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.解答:原创 2014-05-24 09:54:08 · 524 阅读 · 0 评论 -
[LeetCode] 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:"((()))", "(()())", "(())()", "()(()原创 2014-06-07 16:32:08 · 658 阅读 · 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 reach the原创 2014-06-12 23:30:50 · 676 阅读 · 0 评论 -
[LeetCode] Minimum Path Sum
题目: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.Note: You can only move either down or原创 2014-06-14 14:35:30 · 710 阅读 · 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.原创 2014-06-16 10:39:23 · 782 阅读 · 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-06-03 16:20:00 · 774 阅读 · 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-06-16 09:46:19 · 773 阅读 · 0 评论 -
[LeetCode] 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,原创 2014-06-15 09:24:47 · 759 阅读 · 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?解答:原创 2014-06-14 16:05:54 · 770 阅读 · 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-06-15 11:22:55 · 798 阅读 · 0 评论 -
[LeetCode] Path Sum
题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree原创 2014-06-15 10:53:43 · 697 阅读 · 0 评论 -
[LeetCode] 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-06-14 08:59:01 · 1432 阅读 · 0 评论 -
[LeetCode] Maximum Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−原创 2014-05-24 11:22:14 · 783 阅读 · 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-05-24 16:53:44 · 504 阅读 · 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-05-22 15:41:44 · 640 阅读 · 0 评论 -
[LeetCode] 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 (i原创 2014-05-22 09:31:14 · 1017 阅读 · 0 评论 -
[LeetCode] Reverse Integer
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321解答:class Solution {public: int reverse(int x) { int flag = 1; int resul原创 2014-05-22 09:14:32 · 1102 阅读 · 1 评论 -
[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.解答:原创 2014-05-22 08:44:28 · 654 阅读 · 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-05-22 08:40:27 · 599 阅读 · 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.解答:原创 2014-05-22 08:35:47 · 744 阅读 · 0 评论 -
[LeetCode] Sort Colors
题目:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the原创 2014-06-04 08:37:37 · 648 阅读 · 0 评论 -
[LeetCode] Gray Code
题目: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 number of bits in the code, print the seque原创 2014-06-03 08:49:19 · 805 阅读 · 0 评论 -
[LeetCode] Populating Next Right Pointers in Each Node
题目:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next原创 2014-05-23 09:12:08 · 3023 阅读 · 3 评论 -
[LeetCode] 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 t原创 2014-05-23 10:07:14 · 572 阅读 · 0 评论 -
[LeetCode] 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原创 2014-05-24 14:35:03 · 1116 阅读 · 0 评论 -
[LeetCode] Pascal's Triangle
题目:解法:class Solution {public: vector> generate(int numRows) { vector> triangle; vector triangle_cell; if(numRows == 0) { return triangle; }原创 2014-05-24 14:13:12 · 697 阅读 · 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-05-24 16:32:30 · 687 阅读 · 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.原创 2014-05-24 13:49:31 · 867 阅读 · 0 评论 -
[LeetCode] 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 len原创 2014-05-24 12:55:08 · 636 阅读 · 0 评论 -
[LeetCode] Binary Tree Inorder Traversal [递归版]
题目:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursiv原创 2014-05-23 08:10:17 · 672 阅读 · 0 评论 -
[LeetCode] Binary Tree Preorder Traversal [递归版]
题目: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: Recursi原创 2014-05-23 07:29:37 · 845 阅读 · 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?解答:/** * Definition for singly-linked list. * struct ListNode { *原创 2014-05-23 07:49:49 · 671 阅读 · 0 评论 -
[LeetCode] Sum Root to Leaf Numbers
题目:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find原创 2014-06-17 22:22:40 · 863 阅读 · 0 评论