网站吸引流量的方法,大淘客网站建设app,wordpress暗箱,装饰网站开发背景题目来源#xff1a; leetcode题目#xff0c;网址#xff1a;2729. 判断一个数是否迷人 - 力扣#xff08;LeetCode#xff09;
解题思路#xff1a; 对 n#xff0c;2*n#xff0c;3*n 中的数字出现次数计数#xff0c;若数字 0 出现 0 次#xff0c;数字 1~9…题目来源 leetcode题目网址2729. 判断一个数是否迷人 - 力扣LeetCode
解题思路 对 n2*n3*n 中的数字出现次数计数若数字 0 出现 0 次数字 1~9 出现 1 次返回true否则返回 false。
解题代码
class Solution {public boolean isFascinating(int n) {int[] countnew int[10];bitCount(n,count);bitCount(2*n,count);bitCount(3*n,count);if(count[0]!0){return false;}for(int i1;i10;i){if(count[i]!1){return false;}}return true;}public void bitCount(int n,int[] count){while(n!0){count[n%10];nn/10;}}
} 总结 无官方题解。