LeetCode 202. Happy Number

来源:互联网 发布:服务器软件下载 编辑:程序博客网 时间:2024/06/17 17:39
public class Solution {    public boolean isHappy(int n) {        List<Integer> list = new ArrayList<Integer>();        while (!list.contains(n)) {        list.add(n);        int tmp = 0;        int l = String.valueOf(n).length();        for (int i = 0; i < l; i++){        tmp += Math.pow(n % 10, 2);        n = n / 10;        }    n = tmp;        if (n == 1) return true;        }        return false;    }}

0 0