【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 ...
随机推荐
- 基于RestOn智能睡眠监测器的睡眠监测系统
一.项目地址为: https://github.com/linqian123... 二.项目功能概述: 该项目实现的是一个基于RestOn智能睡眠监测器的睡眠监测系统.RestOn智能睡眠检测器通过W ...
- IE版本判断条件注释
IE下判断IE版本的语句...[if lte IE 8]……[endif] <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 < ...
- [Google Guava] 7-原生类型
原文链接 译文链接 译者:沈义扬,校对:丁一 概述 Java的原生类型就是指基本类型:byte.short.int.long.float.double.char和boolean. 在从Guava查找原 ...
- //点击按钮加减音频音量到最小会出现bug什么意思???
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- redis系列(二):数据操作
1.string类型 字符串类型是Redis中最为基础的数据存储类型,它在Redis中是二进制安全的,这便意味着该类型可以接受任何格式的数据,如JPEG图像数据或Json对象描述信息等.在Redis中 ...
- C语言学习笔记7-字符串
本系列文章由jadeshu编写,转载请注明出处.http://blog.csdn.net/jadeshu/article/details/50752405 作者:jadeshu 邮箱: jades ...
- 下载安装Xocde并创建一个C语言的项目工程
安装好Xcode后,新建工程 选择command line tool 选择c语言 点击创建 可以设置运行平台版本 设置 设置c标准 去掉c++ 支持 打开编辑页面 运行 参考: https://www ...
- JavaWeb_(Spring框架)整合Mybatis加入事务操作数据库
整合Mybatis a)导包: i.Spring:基本包.aop.aspects.jdbc.tx.test: ii.Mybatis:mybatis-3.4.6 iii.整合包:mybatis-spri ...
- PHP 之快递100接口封装
<?php /** * Created by PhpStorm. * User: Yang * Date: 2019/8/23 * Time: 10:38 */ class Kuaidi_Que ...
- 编译工具链,生成各个平台的ffmpeg版本的库
1.在开始动手编译ffmpeg之前我们来梳理一下几个概念,gcc.g++.msvc.mingw.clang.cmake.make.qmake 作为一个windows软件工程师,以为长时间浸淫在各种强大 ...