题目链接:happy-number
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 numbe...
分类:
移动开发 时间:
2015-04-26 10:53:59
阅读次数:
123
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 square...
分类:
移动开发 时间:
2015-04-25 00:21:22
阅读次数:
153
我觉得这个算法比较陌生,对我不是简单题目public class Solution { public boolean isHappy(int n) { // 这个叫“模拟”的算法是什么http://meetqun.com/thread-8853-1-1.html H...
分类:
移动开发 时间:
2015-04-24 14:09:39
阅读次数:
119
用Java来处理高精度问题,相信对很多ACMer来说都是一件很happy的事,简单易懂。用Java刷了一些题,感觉Java还不错,在处理高精度和进制转换中,调用库函数的来处理。下面是写的一些Java中一些基本的函数的及其……头文件:import java.io.*;import java.util....
分类:
编程语言 时间:
2015-04-24 11:54:48
阅读次数:
125
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 o...
分类:
移动开发 时间:
2015-04-24 09:03:57
阅读次数:
117
题目链接:https://leetcode.com/problems/happy-number/这道题看上去很简单,如果用hashtable的话,不少童鞋应该都能做出来。只要想明白一件事儿,循环结束的条件:要么当前的数字为1,要么当前的数字曾经出现过。(至于为什么一定会出现循环,额,数学家们已有讨论...
分类:
移动开发 时间:
2015-04-24 00:58:20
阅读次数:
181
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...
分类:
移动开发 时间:
2015-04-23 21:46:26
阅读次数:
222
/* 题意:判断一个数是不是happy数(用这个数每一位的平方的和代替这个数, 不断重复这个过程,如果最后这个数是1,那么这个数就是happy数) 解法:用map容器映射一下,判断当前数是否在前面出现过,如果出现过那么 这个数就不是happy数,不过这样子的空间复杂度太高*/...
分类:
移动开发 时间:
2015-04-23 21:27:21
阅读次数:
135
说实话,如果不看别人的解答的话,这道题我也是没有思路,不知道该循环几次,也不知道循环的终止条件,后来才知道,【2-6】这个范围内的数字都不是happy number
所以就有了终止条件,n>6就是终止条件,当n跳进这个范围内的时候就终止循环,最后就能判断是否是happy number了#include
#include
bool isHappy(int n)
{
while(n>6)...
分类:
移动开发 时间:
2015-04-23 17:37:36
阅读次数:
136
题目:
实现一个函数,把字符串中的每个空格替换成“%20”。加入输入“we are happy.”,则输出“we%20are%20happy.”。
时间复杂度为O(n^2)
基本思想:从前往后把字符串中的空格替换成%20.
假设字符串的长度为n,对每个空格字符,需要移动后面O(n)个字符,因此总的时间复杂度为O(n^2)。
时间复杂度为O(n)
基本思想:先遍历...
分类:
其他好文 时间:
2015-04-23 15:52:12
阅读次数:
204