摘要: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.首先是罗马字符串的特点:羅馬數字共有7個,即I(1)、V(5)、X(10)、L(50)、... 阅读全文
posted @ 2015-10-08 13:40 eversliver 阅读(275) 评论(0) 推荐(0) 编辑
摘要: 考虑下面这种经常出现的使用方式:class webBroswer{public: ... void clearCache(); void clearHistory(); void removeCookies(); ...};那么很自然的就会想到增加这么一种清理方式:cl... 阅读全文
posted @ 2015-10-07 22:40 eversliver 阅读(285) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to thedefinition of LCA on Wikipedia: “The lowest ... 阅读全文
posted @ 2015-10-07 22:13 eversliver 阅读(328) 评论(0) 推荐(0) 编辑
摘要: Given a non-negative integernum, repeatedly add all its digits until the result has only one digit. For example: Givennum = 38, the process is lik... 阅读全文
posted @ 2015-10-07 17:28 eversliver 阅读(432) 评论(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-10-07 17:02 eversliver 阅读(497) 评论(0) 推荐(0) 编辑
摘要: protected成员变量的封装性并非高于public变量。如果有个public的成员变量,一旦其需要改变,那么所有使用它的代码都需要改变。如果有个protected的成员变量,一点其需要改变,那么所有的继承自他的derived class都需要重新改变。这与上面孰轻孰重其实不重要所以说,往往只有两... 阅读全文
posted @ 2015-10-07 14:52 eversliver 阅读(218) 评论(0) 推荐(0) 编辑
摘要: //先看看下面这个例子class Rational{public: Rational(int num, int denu) :numirator(num), denumirator(denu); const Rational operator*(const Rational & l... 阅读全文
posted @ 2015-10-07 14:36 eversliver 阅读(304) 评论(0) 推荐(0) 编辑
摘要: Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For examp... 阅读全文
posted @ 2015-10-07 10:56 eversliver 阅读(225) 评论(0) 推荐(0) 编辑
摘要: Count the number of prime numbers less than a non-negative number,n.计算小于n的质数的个数,当然就要用到大名鼎鼎的筛法了,代码如下,写的有点乱不好意思。 1 class Solution { 2 public: 3 int ... 阅读全文
posted @ 2015-10-06 22:17 eversliver 阅读(466) 评论(0) 推荐(0) 编辑
摘要: 注意一下,c++的底层编译器而言,引用类型往往都是由指针来实现出来的,所以pass-by-reference实际意义上往往是传递了一个指针,这对于c++的内置类型来说往往传递一个reference更加昂贵一点。但是这不能成为对所有的小对象不使用pass-by-reference的理由。小结:1. 尽... 阅读全文
posted @ 2015-10-06 20:58 eversliver 阅读(290) 评论(0) 推荐(0) 编辑