10 2015 档案

摘要:Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 v2) return 1; else if(v2 > v1) ... 阅读全文
posted @ 2015-10-31 19:31 dylqt 阅读(158) 评论(0) 推荐(0)
摘要: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 off ... 阅读全文
posted @ 2015-10-30 16:26 dylqt 阅读(126) 评论(0) 推荐(0)
摘要:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the c... 阅读全文
posted @ 2015-10-30 16:24 dylqt 阅读(101) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings.class Solution {public: string longestCommonPrefix(vector& st... 阅读全文
posted @ 2015-10-30 09:05 dylqt 阅读(97) 评论(0) 推荐(0)
摘要:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below a... 阅读全文
posted @ 2015-10-29 18:49 dylqt 阅读(214) 评论(0) 推荐(0)
摘要:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are s... 阅读全文
posted @ 2015-10-29 16:42 dylqt 阅读(117) 评论(0) 推荐(0)
摘要:Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinki... 阅读全文
posted @ 2015-10-29 13:41 dylqt 阅读(133) 评论(0) 推荐(0)
摘要:Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 –> AB class Solution... 阅读全文
posted @ 2015-10-29 09:36 dylqt 阅读(137) 评论(0) 推荐(0)
摘要:Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 要求时间复杂度为log型 int trailingZeroes(int n) { int ret = 0; while(n) ... 阅读全文
posted @ 2015-10-27 09:19 dylqt 阅读(122) 评论(0) 推荐(0)
摘要:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".char* addBinary(char* a, char* b) { int a... 阅读全文
posted @ 2015-10-26 17:20 dylqt 阅读(146) 评论(0) 推荐(0)
摘要:Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is... 阅读全文
posted @ 2015-10-25 08:58 dylqt 阅读(160) 评论(0) 推荐(0)
摘要: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 { public: vector... 阅读全文
posted @ 2015-10-24 10:49 dylqt 阅读(95) 评论(0) 推荐(0)
摘要:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional... 阅读全文
posted @ 2015-10-23 21:29 dylqt 阅读(144) 评论(0) 推荐(0)
摘要: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. 用一个数组中的每个值连起来作为一个数,把这个数加1... 阅读全文
posted @ 2015-10-23 09:09 dylqt 阅读(129) 评论(0) 推荐(0)
摘要:一、概述1、面向对象程序设计的核心思想:数据抽象、继承和动态绑定数据抽象:将类的接口与实现分离继承:可以定义相似的类型并对相似关系建模动态绑定:可以一定程度上忽略类似类型的区别,而以同一的方式使用它们的对象2、当使用基类的引用(或指针)调用一个虚函数时将发生动态绑定二、虚函数1、基类希望它的派生类各... 阅读全文
posted @ 2015-10-22 21:01 dylqt 阅读(189) 评论(0) 推荐(0)
摘要:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially filled sudoku ... 阅读全文
posted @ 2015-10-18 13:35 dylqt 阅读(114) 评论(0) 推荐(0)
摘要:Description: Count the number of prime numbers less than a non-negative number, n. 找出小于n的质数的和 int countPrimes(int n) { int count = 0; if(n num(n - 1, true); num[0] = false; ... 阅读全文
posted @ 2015-10-18 09:23 dylqt 阅读(172) 评论(0) 推荐(0)
摘要:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k. class So... 阅读全文
posted @ 2015-10-17 18:54 dylqt 阅读(128) 评论(0) 推荐(0)
摘要:Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. Exampl... 阅读全文
posted @ 2015-10-17 11:31 dylqt 阅读(158) 评论(0) 推荐(0)
摘要: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 20 / \ ... 阅读全文
posted @ 2015-10-16 14:58 dylqt 阅读(135) 评论(0) 推荐(0)
摘要:一、基本概念1、重载运算符是具有特殊名字的函数:由关键字operator和其他要定义的运算符号共同组成2、重载运算符的参数数量与该运算符作用的运算对象一样多当一个重载的运算符是成员函数时,this会绑定到左侧运算对象,成员运算符函数的显示参数数量比运算对象的数量少一个3、对于一个运算符函数,它要么是... 阅读全文
posted @ 2015-10-16 12:28 dylqt 阅读(252) 评论(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, replace the number by the sum of the squares of... 阅读全文
posted @ 2015-10-16 09:30 dylqt 阅读(165) 评论(0) 推荐(0)
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between t... 阅读全文
posted @ 2015-10-15 20:15 dylqt 阅读(149) 评论(0) 推荐(0)
摘要: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 But the following is ... 阅读全文
posted @ 2015-10-15 16:06 dylqt 阅读(151) 评论(0) 推荐(0)
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9to 4 / \ 7 2 / \ / \ 9 6 3 1 /** * Definition for a binary tree node. * struct TreeNode { * int val; ... 阅读全文
posted @ 2015-10-15 08:51 dylqt 阅读(125) 评论(0) 推荐(0)
摘要:一、拷贝控制操作 1、拷贝构造函数:一个构造函数的一个参数是自身类类型的引用,且额外参数都有默认值 class Foo{ public: Foo(const Foo&); //拷贝构造函数;必须引用类型;最好是const类型;不应该是explicit的 } 拷贝构造函数通常会被隐式使用,所以不应该是explicit 如果我们没有为一个类定义拷贝构造函数,编译器会定义一个... 阅读全文
posted @ 2015-10-14 22:17 dylqt 阅读(237) 评论(0) 推荐(0)
摘要:Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are:["1->2->5", "1->3"] /** * Definition for a bin... 阅读全文
posted @ 2015-10-12 18:28 dylqt 阅读(160) 评论(0) 推荐(0)
摘要: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. /** * Definition for a binary tree node... 阅读全文
posted @ 2015-10-12 10:20 dylqt 阅读(197) 评论(0) 推荐(0)
摘要: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. F 阅读全文
posted @ 2015-10-11 21:38 dylqt 阅读(149) 评论(0) 推荐(0)
摘要: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 an... 阅读全文
posted @ 2015-10-11 21:13 dylqt 阅读(139) 评论(0) 推荐(0)
摘要:一、动态内存与智能指针 1、new:在动态内存中为对象分配空间并返回一个指向该对象的指针;delete:接受一个动态对象的指针,销毁该对象,并释放与之关联的内存 2、两种指针:shared_ptr和unique_ptr;还有一个weak_ptr;都定义在memory中 二、shared_ptr类:智... 阅读全文
posted @ 2015-10-11 18:57 dylqt 阅读(303) 评论(0) 推荐(0)
摘要:一、概述 1、关联容器中的元素是按关键字来保存和访问的;顺序容器中的元素是按它们在容器中的位置来顺序保存和访问的 2、关联容器:map和set map:元素是:关键字-值的对 set:每个元素只包含一个关键字 multimap:关键字可重复出现的map multiset:关键字可重复出现的set unordered_map:用哈希函数组织的map unordered_set:用哈希函数... 阅读全文
posted @ 2015-10-10 18:53 dylqt 阅读(199) 评论(0) 推荐(0)
摘要:#ifndef _Tree_H#define _Tree_Htypedef int ElementType;typedef struct TreeNode{ ElementType Element; struct TreeNode *Left; struct TreeNode *R... 阅读全文
posted @ 2015-10-09 11:01 dylqt 阅读(196) 评论(0) 推荐(0)
摘要:一、概述 1、大多数算法都定义在头文件algorithm中;头文件numeric中定义了一组数值泛型算法 2、一般情况下,这些算法并不直接操作容器,而是遍历两个迭代器指定的一个元素范围 算法永远不会改变底层容器的大小,想要改变必须使用容器自带的操作 二、初识泛型算法 1、理解算法最基本的方法是了解他们是否读取元素、改变元素或是重排元素顺序 2、那些只接受一个单一迭代器来作为第二个序列的算法,都假... 阅读全文
posted @ 2015-10-07 20:18 dylqt 阅读(196) 评论(0) 推荐(0)
摘要:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after calling your fun... 阅读全文
posted @ 2015-10-07 16:06 dylqt 阅读(136) 评论(0) 推荐(0)