题目很简单,就是用哈希表存,判断有没有重复 学到了:java中字符串的比较有两种: 1.==这种是比较引用,只用两个字符串变量指向同一个地址才相等 2..equals()这种是值的比较,只要两个字符串一样就相等 Set<String> set = new HashSet<>(); String temp = n+""; while (!Objects.equals(temp, "1")) { if (set.contains(temp)) b…
Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the…
今天先谈下弗洛伊德判环,弗洛伊德判环原来是在一个圈内有两人跑步,同时起跑,一人的速度是另一人的两倍,则那个人能在下一圈追上另一个人,弗洛伊德判环能解数字会循环出现的题,比如说判断一个链表是不是循环链表.在程序中具体表现为 one = change(one); //一倍速度 two = change(change(two));//两倍速度 即一倍速度的人调用生成函数change一次,两倍速度的人调用生成函数change两次. Leetcode 202 Happy Number 就是这样一道简单的题…
题目: Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until…
1.判断是否数字 /// 判断是否是数字 /// /// - Parameter string: <#string description#> /// - Returns: <#return value description#> class func isPurnInt(string: String) -> Bool { let scan: Scanner = Scanner(string: string) return scan.scanInt(&val) &am…
public class StringClassTest { public static void main(String[] args) { //遍历字符串 String str = "Hello world"; for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); System.out.print(ch+" "); } System.out.println(); //在字符串里查…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 [LeetCode] 题目地址:https://leetcode.com/problems/happy-number/ Total Accepted: 36352 Total Submissions: 109782 Difficulty: Easy 题目描述 Write an algorithm to determine if a…
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, Given nums = [0, 1, 3] return 2. Note: Your algorithm should run in linear runtime complexity. Could you implement it u…
JavaScript 判断一个数字是否含有小数点,如果含有,则返回该数字:如果不含小数点,则小数点后保留两位有效数字: function hasDot(num){ if(!isNaN(num)){ return ( (num + '').indexOf('.') != -1 ) ? num: num.toFixed(2); } } var num = 16; console.log(hasDot(num)); // 16.00 var num2 = 18.01; console.log(hasD…
jq 判断输入数字 <input   id="N_source" name="N_source"   type="text" value=""> $("#N_source").keyup( function(){ dsds(this); }); function dsds(r){ if (!(/^[0-9]*$/g.test( r.value.substr(r.value.length-1,1)…