Files
2020-08-09 00:39:24 +08:00

29 lines
845 B
Markdown
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [633. Sum of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers/)
## 题目
Given a non-negative integer `c`, your task is to decide whether there're two integers `a` and `b` such that a^2 + b^2 = c.
**Example 1:**
Input: 5
Output: True
Explanation: 1 * 1 + 2 * 2 = 5
**Example 2:**
Input: 3
Output: False
## 题目大意
给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b使得 a^2 + b^2 = c。
## 解题思路
- 给出一个数,要求判断这个数能否由由 2 个完全平方数组成。能则输出 true不能则输出 false。
- 可以用二分搜索来解答这道题。判断题意,依次计算 `low * low + high * high` 和 c 是否相等。从 [1, sqrt(n)] 区间内进行二分,若能找到则返回 true找不到就返回 false 。