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. 将字符串s='ab34aa243dd78eww89' 处理为 '**34**243**78***89',然后对数字求和,结果为'**7**9**15***17'

    s='ab34aa243dd78eww89'#s='ab34aa000dd78eww89' #方法1: result='' for i in s: if i.isalpha(): result+='* ...

  2. springboot中,使用redisTemplate操作redis

    知识点: springboot中整合redis springboot中redisTemplate的使用 redis存数据时,key出现乱码问题 一:springboot中整合redis (1)pom. ...

  3. java之数据结构与算法

    1.了解基本数据结构及特点 如,有哪些二叉树,各有什么特点 树二叉搜索树 每个节点都包含一个值,每个节点至多有两棵子树,左孩子小于自己,右孩子大于自己,时间复杂度是O(log(n)),随着不断插入节点 ...

  4. [译] 尤雨溪:Vue 3.0 计划

    [译] 尤雨溪:Vue 3.0 计划 原文:Plans for the Next Iteration of Vue.js作者:Evan You 发表时间:Sep 30, 2018译者:西楼听雨 发表时 ...

  5. C# 可观察集合

    static void Main() { var data = new ObservableCollection<string>(); data.CollectionChanged += ...

  6. AbstractWrapper ,EntityWrapper, QueryWrapper, UpdateWrappe

    https://blog.csdn.net/qq_42112846/article/details/88086035 https://blog.csdn.net/m0_37034294/article ...

  7. web批量下载文件到本地

    JavaWeb 文件下载功能 文件下载的实质就是文件拷贝,将文件从服务器端拷贝到浏览器端,所以文件下载需要IO技术将服务器端的文件读取到,然后写到response缓冲区中,然后再下载到个人客户端. 1 ...

  8. learning express step(十四)

    learning express error handle code: const express = require('express'); const app = express(); const ...

  9. MySQL区间检索

    在没有前端的情况下,自己写一些搜索逻辑,可能不太完善,不过功能完成了 //区间检索的判定 private String columnTextTranslateRegion(String columnT ...

  10. C语言学习笔记5-程序结构

    本系列文章由jadeshu编写,转载请注明出处.http://blog.csdn.net/jadeshu/article/details/50752148 作者:jadeshu   邮箱: jades ...