problem

solution:
/*
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的更多相关文章

  1. 【LeetCode】507. Perfect Number 解题报告(Python & Java & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)

    [LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...

  3. 【LeetCode】137. Single Number II 解题报告(Python)

    [LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...

  4. 【LeetCode】306. Additive Number 解题报告(Python)

    [LeetCode]306. Additive Number 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...

  5. 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)

    [LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...

  6. 【LeetCode】65. Valid Number

    Difficulty: Hard  More:[目录]LeetCode Java实现 Description Validate if a given string can be interpreted ...

  7. 【LeetCode】279. Perfect Squares 解题报告(C++ & Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 四平方和定理 动态规划 日期 题目地址:https: ...

  8. 【Leetcode】179. Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  9. 【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 ...

随机推荐

  1. mysql全量和增量备份详解(带脚本)

    在日常运维工作中,对mysql数据库的备份是万分重要的,以防在数据库表丢失或损坏情况出现,可以及时恢复数据. 下面对这种备份方案详细说明下:1.MySQLdump增量备份配置执行增量备份的前提条件是M ...

  2. js获取文件后缀名

    function extname(filename){ if(!filename||typeof filename!='string'){ return false }; let a = filena ...

  3. 系统分析与设计结对项目——WordCount

    结对项目完成WordCount 合作者:201631062507  201631062526(学号) 代码地址:https://gitee.com/WordCountMC/WordCountTeam ...

  4. Linux下恢复误删除的文件

    原文地址:http://www.libenfu.com/vim-分区下误删的文件,恢复文件全记录-转 当时我的工作目录是/source/needrecovered. $ pwd /source/nee ...

  5. JavaScript 基础知识 - BOM篇

    前言 本篇文章是JavaScript基础知识的BOM篇,如果前面的<JavaScript基础知识-DOM篇>看完了,现在就可以学习BOM了. 注意: 所有的案例都在这里链接: 提取密码密码 ...

  6. c#动态调用WEBSERVICE接口

    C#动态webservice调用接口 1 using System; 2 using System.Collections; 3 using System.IO; 4 using System.Net ...

  7. Java8-Lock-No.01

    import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util ...

  8. C++ extern关键字

    [参考] 关于C++中extern的简单笔记

  9. P3474 [POI2008]KUP-Plot purchase

    思路:单调栈 提交:>5次 错因:单调栈写法有问题+前缀和写错 题解: 若有\(>=k\ \&\&\ <=2\times k\)的点,显然直接选他就行了. 否则,我们 ...

  10. Oracle 后台进程(三)LGWR进程

    一.LGWR进程简介 LGWR,是Log Writer的缩写,也是一种后台进程.主要负责将日志缓冲内容写到磁盘的在线重做日志文件或组中.DBWn将dirty块写到磁盘之前,所有与buffer修改相关的 ...