【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 ...
随机推荐
- NLP学习(3)---Bert模型
一.BERT模型: 前提:Seq2Seq模型 前提:transformer模型 bert实战教程1 使用BERT生成句向量,BERT做文本分类.文本相似度计算 bert中文分类实践 用bert做中文命 ...
- Reservoir Sampling 蓄水池采样算法
https://blog.csdn.net/huagong_adu/article/details/7619665 https://www.jianshu.com/p/63f6cf19923d htt ...
- jaxb生成pojo类返回类型为布尔值的问题
返回值为Boolean的话回在对象转json的时候丢失掉这个属性,因为json认的是小写. 这个算jaxb的一个bug:https://java.net/jira/browse/JAXB-510 解决 ...
- c++对c的扩展----什么时候分配内存
const分配内存的时机,编译器编译的时候分配内存 const相当于宏,用来取代c语言的#define #include<iostream> using namespace std; vo ...
- 10、组件注册-@Import-使用ImportBeanDefinitionRegistrar
10.组件注册-@Import-使用ImportBeanDefinitionRegistrar public interface ImportBeanDefinitionRegistrar { /** ...
- learning express step(十四)
learning express error handle code: const express = require('express'); const app = express(); const ...
- C++泛型编程-扩展
类型做参数是C++模板实现的主要形式.由此实现了类模板-->模板类-->实例的过程 当然除此之外也可以参考bitset的实现方式,参数决定类型的做法. #include <iostr ...
- (转)实验文档3:在kubernetes集群里集成Apollo配置中心
使用ConfigMap管理应用配置 拆分环境 主机名 角色 ip HDSS7-11.host.com zk1.od.com(Test环境) 10.4.7.11 HDSS7-12.host.com zk ...
- 字典-Python基础前传(9)
(一)Python中为什么要有字典 jacky说科学存在的逻辑只有两个: 1.解释问题 2.解决问题 我们明白了科学的逻辑,我们理解任何的知识和技能,都是很简单的 之前jacky跟大家说list因为太 ...
- 使用Flask设计带认证token的RESTful API接口
大数据时代 Just a record. 使用Flask设计带认证token的RESTful API接口[翻译] 上一篇文章, 使用python的Flask实现一个RESTful API服务器端 简 ...