[LeetCode]633. Sum of Square Numbers
来源:互联网 发布:在淘宝卖手机 编辑:程序博客网 时间:2024/06/05 15:32
[LeetCode]633. Sum of Square Numbers
题目描述
思路
有点类似tow sum 从两边找,low的边界是0,high的边界是输入num的平方根取整
代码
#include <iostream>#include <vector>#include <algorithm>using namespace std;class Solution {public: bool judgeSquareSum(int c) { int high = sqrt(c), low = 0; while (low <= high) { int res = low * low + high * high; if (res == c) return true; else if (res < c) ++low; else --high; } return false; }};int main() { int num; Solution s; while (cin >> num) { cout << s.judgeSquareSum(num) << endl; }}
阅读全文
0 0
- [leetcode]633. Sum of Square Numbers
- [LeetCode]633. Sum of Square Numbers
- LeetCode 633. Sum of Square Numbers
- [leetcode]633. Sum of Square Numbers
- leetcode 633. Sum of Square Numbers
- LeetCode 633. Sum of Square Numbers
- leetcode 633. Sum of Square Numbers
- leetcode 633. Sum of Square Numbers
- [LeetCode]633. Sum of Square Numbers
- leetcode[Sum of Square Numbers]
- 633. Sum of Square Numbers
- 633. Sum of Square Numbers
- 633. Sum of Square Numbers
- 633. Sum of Square Numbers
- 633. Sum of Square Numbers
- 633. Sum of Square Numbers。
- 【leetcode】633. Sum of Square Numbers(Python & C++)
- leetcode 633. Sum of Square Numbers 二分查找
- 邮件系统搭建---邮件服务器Apache James Server 安装、将数据库改变为MySql
- 转载转载 非对称加密算法RSA http://snowolf.iteye.com/blog/379860
- YOLOv2—更改CelebA数据集的bbox [by zhangzexuan][17.9.24updated]
- ListView基本使用
- 2.3 线性表的链式存储结构(链表)
- [LeetCode]633. Sum of Square Numbers
- 【详解】SPI中的极性CPOL和相位CPHA是什么以及如何设置
- npm更新和nodejs更新
- 构造函数与析构函数的调用
- MSP430学习笔记:UART
- 2017/09/19 百度面试
- Struts 2
- 魅族手机权限开启方法6
- Kotlin 类和对象