摘要: 题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断该数组中是否有该整数。算法流程如下:比如一个二维数组array:1 1 2 8 92 3 2 4 9 124 5 4 7 10 136 7 6 8 1... 阅读全文
posted @ 2015-07-20 22:35 vpoet 阅读(227) 评论(0) 推荐(0)
摘要: #ifndef,#define,#end 是宏定义的一种---条件编译这样我直接举个例子好了:我定义两个相同的类A分别在single.h和singlenew.hsingle.h: 1 #include 2 using namespace std; 3 4 class A 5 { 6 public... 阅读全文
posted @ 2015-07-20 21:47 vpoet 阅读(1008) 评论(0) 推荐(0)
摘要: 题目:设计一个类,我们只能生成该类的一个实例这道题显然是对设计模式的考察,很明显是单例模式。什么是单例模式呢,就是就像题目所说的只能生成一个类的实例。那么我们不难考虑到下面几点:1.不能new多个对象,那么必然该类的构造函数是私有的2.类对象只有一个,那么必然该对象只能有一个私有的静态成员变量,该成... 阅读全文
posted @ 2015-07-20 21:16 vpoet 阅读(233) 评论(0) 推荐(0)
摘要: 题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数 1 class CMyString 2 { 3 public: 4 CMyString(char *pData=NULL); 5 CMyString(const CMyString & str); 6 ~... 阅读全文
posted @ 2015-07-20 20:37 vpoet 阅读(244) 评论(0) 推荐(0)
摘要: Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文
posted @ 2015-07-20 09:33 vpoet 阅读(174) 评论(0) 推荐(1)
摘要: Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come... 阅读全文
posted @ 2015-07-20 09:32 vpoet 阅读(157) 评论(0) 推荐(0)
摘要: Implementint sqrt(int x).Compute and return the square root ofx. 1 int mySqrt(int x) 2 { 3 if(x==1) 4 return 1; 5 6 /* for(int i=2;i<... 阅读全文
posted @ 2015-07-20 09:31 vpoet 阅读(129) 评论(0) 推荐(0)
摘要: Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --... 阅读全文
posted @ 2015-07-20 09:30 vpoet 阅读(205) 评论(0) 推荐(1)
摘要: Implement pow(x,n).1 double myPow(double x, int n) 2 {3 if(n==0) 4 return 1.0; 5 if(n<0) 6 return 1.0/pow(x,-n); 7 ret... 阅读全文
posted @ 2015-07-20 09:29 vpoet 阅读(127) 评论(0) 推荐(0)
摘要: Sort a linked list using insertion sort. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * struct ListNo... 阅读全文
posted @ 2015-07-20 09:29 vpoet 阅读(173) 评论(0) 推荐(0)
摘要: Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great... 阅读全文
posted @ 2015-07-20 09:28 vpoet 阅读(149) 评论(0) 推荐(0)
摘要: Given an integer, write a function to determine if it is a power of two. 1 bool isPowerOfTwo(int n) 2 { 3 if(n1)10 {11 if(n%2==0)12 ... 阅读全文
posted @ 2015-07-20 09:27 vpoet 阅读(159) 评论(0) 推荐(0)
摘要: 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... 阅读全文
posted @ 2015-07-20 09:23 vpoet 阅读(228) 评论(0) 推荐(0)
摘要: Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matri... 阅读全文
posted @ 2015-07-20 09:22 vpoet 阅读(276) 评论(0) 推荐(0)
摘要: 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 mat... 阅读全文
posted @ 2015-07-20 09:21 vpoet 阅读(146) 评论(0) 推荐(0)
摘要: Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh... 阅读全文
posted @ 2015-07-20 09:20 vpoet 阅读(184) 评论(0) 推荐(0)
摘要: Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor... 阅读全文
posted @ 2015-07-20 09:20 vpoet 阅读(185) 评论(0) 推荐(0)
摘要: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 1 class Solution { 2 public: 3 int roma... 阅读全文
posted @ 2015-07-20 09:19 vpoet 阅读(145) 评论(0) 推荐(0)
摘要: 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, retu... 阅读全文
posted @ 2015-07-20 09:18 vpoet 阅读(136) 评论(0) 推荐(0)
摘要: Given an array of integers, every element appearsthreetimes except for one. Find that single one. 1 int singleNumber(int* nums, int numsSize) 2 { 3 ... 阅读全文
posted @ 2015-07-20 09:17 vpoet 阅读(138) 评论(0) 推荐(0)
摘要: Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the arr... 阅读全文
posted @ 2015-07-20 09:16 vpoet 阅读(134) 评论(0) 推荐(0)
摘要: Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1 1 /** 2 * Definition for a binary tre... 阅读全文
posted @ 2015-07-20 09:15 vpoet 阅读(203) 评论(0) 推荐(0)
摘要: Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the arr... 阅读全文
posted @ 2015-07-20 09:13 vpoet 阅读(183) 评论(0) 推荐(0)
摘要: Given a linked list, determine if it has a cycle in it. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ... 阅读全文
posted @ 2015-07-20 09:12 vpoet 阅读(137) 评论(0) 推荐(0)
摘要: Write a function that takes an unsigned integer and returns the number of ’1' bits it hasFor example, the 32-bit integer ’11' has binary representatio... 阅读全文
posted @ 2015-07-20 09:11 vpoet 阅读(167) 评论(0) 推荐(0)
摘要: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is1 -> 2 -> 3 -> ... 阅读全文
posted @ 2015-07-20 09:08 vpoet 阅读(133) 评论(0) 推荐(0)