【leetcode】507. Perfect Number
problem
/*
class Solution {
public:
bool checkPerfectNumber(int num) {
int sum = 1;
for(int i=2; i*i<=num; i++)
{
if(num%i==0) sum += i + (num/i == i) ? 0 : num/i; //
}
return (sum == num) && (num!=1);
} }; */
class Solution {
public:
bool checkPerfectNumber(int num) {
int sum = ;
for (int i = ; i * i <= num; ++i) {
if (num % i == ) {
sum += i + (num / i == i ? : num / i);
}
}
return num != && sum == num;
}
};
奇怪!!!为什么上边的solution不能accept,改的是一样的哈。。。反正宝宝是没有看出差别在哪里。。。
solution2: 枚举法,哈哈哈
class Solution {
public:
bool checkPerfectNumber(int num) {
return num== || num== || num== || num== || num== ;
}
};
【leetcode】507. Perfect Number的更多相关文章
- 【LeetCode】507. Perfect Number 解题报告(Python & Java & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)
[LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
- 【LeetCode】137. Single Number II 解题报告(Python)
[LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...
- 【LeetCode】306. Additive Number 解题报告(Python)
[LeetCode]306. Additive Number 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...
- 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)
[LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...
- 【LeetCode】65. Valid Number
Difficulty: Hard More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...
- 【LeetCode】279. Perfect Squares 解题报告(C++ & Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 四平方和定理 动态规划 日期 题目地址:https: ...
- 【Leetcode】179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- 【leetcode】1189. Maximum Number of Balloons
题目如下: Given a string text, you want to use the characters of text to form as many instances of the w ...
随机推荐
- devops发展历程
第一阶段:只有 Dev ,没有 Ops ,Dev 是全栈工程师 如何理解?最初的时候,产品和业务形态都处于摸索期,业务复杂度不高,访问量不大,软件能够尽快跑起来推向市场是最重要的,所以架构上不设计的很 ...
- 文件已经传输过来,数据在data,http接收
- PHP 获取上传文件的实际类型
方案一: mime_content_type ( string $filename ) : string (PHP 4 >= 4.3.0, PHP 5, PHP 7) mime_content_ ...
- JAVA遇见HTML——JSP篇:JSP内置对象(上)
JSP九大内置对象 JSP内置对象是Web容器创建的一组对象,不使用new关键就可以使用的内置对象. <% int[] value={60,70,80}; for(int i:value){ o ...
- MVC,MVP 和 MVVM 的图示 - 阮一峰
作者: 阮一峰 日期: 2015年2月 1日 复杂的软件必须有清晰合理的架构,否则无法开发和维护. MVC(Model-View-Controller)是最常见的软件架构之一,业界有着广泛应用.它本身 ...
- [转载]yarn的安装和使用
yarn的安装和使用 2018-08-02 10:45:41 yw00yw 阅读数 50696 文章标签: yarn 更多 分类专栏: 工具 版权声明:本文为博主原创文章,遵循CC 4.0 BY- ...
- Shiro 中的 SecurityUtils(转)
在 Shiro 中 SecurityUtils 是一个抽象类.并且没有任何子类.在其中声明了一个静态属性,三个静态方法. 静态属性 securityManager private static Sec ...
- Task异步
快速示例 class Program { static void Main(string[] args) { //Console.WriteLine("main start..") ...
- python--第五天练习题
# 1.按alist中元素的age由大到小排序 alist = [{'name': 'a', 'age': 20}, {'name': 'b', 'age': 30}, {'name': 'v', ' ...
- codeforces1213F tarjan缩点+拓扑排序
题意 给定两个长度为n的排列p和q,构造一个字符串s满足\(s[p_i]<=s[p_{i+1}]\)和\(s[q_i]<=s[q_{i+1}]\),且满足字符串中不同字符的个数不少于k. ...