摘要:
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)、... 阅读全文
摘要:
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 ... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
Count the number of prime numbers less than a non-negative number,n.计算小于n的质数的个数,当然就要用到大名鼎鼎的筛法了,代码如下,写的有点乱不好意思。 1 class Solution { 2 public: 3 int ... 阅读全文