题目来源:
leetcode题目,网址:2729. 判断一个数是否迷人 - 力扣(LeetCode)
解题思路:
对 n,2*n,3*n 中的数字出现次数计数,若数字 0 出现 0 次,数字 1~9 出现 1 次,返回true;否则返回 false。
解题代码:
- class Solution {
- public boolean isFascinating(int n) {
- int[] count=new int[10];
- bitCount(n,count);
- bitCount(2*n,count);
- bitCount(3*n,count);
- if(count[0]!=0){
- return false;
- }
- for(int i=1;i<10;i++){
- if(count[i]!=1){
- return false;
- }
- }
- return true;
- }
- public void bitCount(int n,int[] count){
- while(n!=0){
- count[n%10]++;
- n=n/10;
- }
- }
- }
总结:
无官方题解。