Kros的博客 Kros的博客
首页
  • CSS
  • 工具
  • Vue
  • js
  • Vue3
  • 算法
  • 折腾笔记
一言
  • 分类
  • 标签
  • 归档
码云

Kros

凡心所向,素履以往,生如逆旅,一苇以航
首页
  • CSS
  • 工具
  • Vue
  • js
  • Vue3
  • 算法
  • 折腾笔记
一言
  • 分类
  • 标签
  • 归档
码云
  • 每日算法

    • 信
    • 独一无二的出现次数
    • 按奇偶排序数组Ⅱ
    • 两数之和
    • 两数相加2
    • 寻找两个正序数组的中位数
    • 二叉树最大深度
    • 洗牌算法
    • 移动零
    • 数组元素排列组合
    • 上升下降字符
    • 最大间距
    • 四数相加2
    • 最大三角周长
    • 在排序数组中查找元素的起始位置
    • 最富有客户的资产总量
    • 打印规定循环字符串
    • 从m个数中选择n个数的组合
    • 复原IP地址
    • 有效的数独
    • 旋转图像
    • 缺失的第一个正整数
    • 第 N 个泰波那契数
    • 轮转数组
    • 爬楼梯
    • 斐波那契数列
    • 使用最小花费爬楼梯
    • 打家劫舍
    • 删除并获得点数
    • 颜色分类
    • 字母异分词分组
    • 加一
    • N叉树的层序遍历
    • N叉树的前序遍历
    • N叉树的后序遍历
    • N叉树的深度
    • 二叉树的中序遍历
    • 和并两个有序数组
    • 移除元素
    • 删除有序数组中的重复项Ⅱ
    • 多数元素
    • 找到数组的中间位置
    • 搜索插入位置
    • 最长连续序列
    • 三数之和
    • 找到字符串中所有字母异位词
    • 有效的括号
    • 最小栈
    • 求出硬币游戏的玩家
    • Find the odd int
    • Regex validate PIN code
    • Find the next perfect square
  • 折腾

  • 分享

  • 随笔
  • 每日算法
kros
2025-09-05

Find the next perfect square

题目: 找出下一个完全平方数

描述: You might know some pretty large perfect squares. But what about the NEXT one?

Complete the findNextSquare method that finds the next integral perfect square after the one passed as a parameter. Recall that an integral perfect square is an integer n such that sqrt(n) is also an integer.

If the argument is itself not a perfect square then return either -1 or an empty value like None or null, depending on your language. You may assume the argument is non-negative.

Examples ( Input --> Output )

121 --> 144
625 --> 676
114 --> -1  #  because 114 is not a perfect square
1
2
3

在线地址:Find the next perfect square!

function findNextSquare(num){
    const sqrtNum = Math.sqrt(num)
    if (Number.isInteger(sqrtNum)) {
        return Math.pow(sqrtNum + 1, 2)
    }
    return  -1
}
1
2
3
4
5
6
7
上次更新: 2025/09/05, 8:09:00
Regex validate PIN code
阿里云效Codeup基础

← Regex validate PIN code 阿里云效Codeup基础→

最近更新
01
Regex validate PIN code
09-05
02
Find the odd int
09-05
03
具体使用与页面渲染
09-03
更多文章>
Theme by Vdoing | Copyright © 2020-2025 kros king
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
icon-heart-o icon-heart icon-infinity icon-pause icon-play link next prev