2013年9月14日

[C++基础]队列<queue>中的常用函数

摘要: 在C++中只要#include即可使用队列类,其中在面试或笔试中常用的成员函数如下(按照最常用到不常用的顺序)1. push2. pop3. size4. empty5. front6. back接下来逐一举例说明:1. push队列中由于是先进先出,push即在队尾插入一个元素,如:1 queue q;2 q.push("Hello World!");3 q.push("China");4 cout q;2 q.push("Hello World!");3 q.push("China");4 q.pop();5 阅读全文

posted @ 2013-09-14 20:26 Horstxu 阅读(89049) 评论(0) 推荐(10) 编辑

2013年9月13日

[leetcode.com]算法题目 - Pow(x, n)

摘要: Implement pow(x,n). 1 class Solution { 2 public: 3 double pow(double x, int n) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if (0==n) return 1.0; 7 if (1==n) return x; 8 9 int k = abs(n);10 int rema... 阅读全文

posted @ 2013-09-13 20:11 Horstxu 阅读(492) 评论(0) 推荐(0) 编辑

2013年9月12日

[leetcode.com]算法题目 - Jump Game

摘要: 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.Determine if you are able to reach the last index.For example:A =[2,3,1,1,4], returntrue.A =[3,2,1,0,4], returnfalse. 1 阅读全文

posted @ 2013-09-12 21:11 Horstxu 阅读(260) 评论(0) 推荐(0) 编辑

[leetcode.com]算法题目 - Pascal's Triangle

摘要: GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]] 1 class Solution { 2 public: 3 vector > generate(int numRows) { 4 // Start typing your C/C++ solution below 5 // DO NOT write in... 阅读全文

posted @ 2013-09-12 20:53 Horstxu 阅读(179) 评论(0) 推荐(0) 编辑

2013年9月11日

[leetcode.com]算法题目 - 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,−1,2,1]has the largest sum =6. 1 class Solution { 2 public: 3 int maxSubArray(int A[], int n) { 4 // Start... 阅读全文

posted @ 2013-09-11 22:27 Horstxu 阅读(201) 评论(0) 推荐(0) 编辑

[leetcode.com]算法题目 - Plus One

摘要: Given a number represented as an array of digits, plus one to the number. 1 class Solution { 2 public: 3 vector plusOne(vector &digits) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 bool allNine = true; 7 int size = digi... 阅读全文

posted @ 2013-09-11 22:18 Horstxu 阅读(241) 评论(0) 推荐(0) 编辑

[leetcode.com]算法题目 - Remove Duplicates from Sorted List

摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode 阅读全文

posted @ 2013-09-11 21:53 Horstxu 阅读(260) 评论(0) 推荐(0) 编辑

[leetcode.com]算法题目 - 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 3But the following is not: 1 / \ 2 2 \ \ 3 3Note:Bonus points if you could solve it both recursively and iterati... 阅读全文

posted @ 2013-09-11 20:37 Horstxu 阅读(189) 评论(0) 推荐(0) 编辑

2013年9月10日

[leetcode.com]算法题目 - Decode Ways

摘要: A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it cou 阅读全文

posted @ 2013-09-10 00:00 Horstxu 阅读(209) 评论(0) 推荐(0) 编辑

2013年9月9日

[leetcode.com]算法题目 - Gray Code

摘要: The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code s 阅读全文

posted @ 2013-09-09 22:57 Horstxu 阅读(422) 评论(0) 推荐(0) 编辑

导航