“Leetcode pair chiffres” Réponses codées

Leetcode pair chiffres

// https://leetcode.com/problems/find-numbers-with-even-number-of-digits/
// Find Numbers with Even Number of Digits

class Solution {
    public int findNumbers(int[] nums) {
        int evenDigits = 0;
        for (int num : nums) {
            if (isEvenDigit(num)) evenDigits++;
        }
        return evenDigits;
    }
/*	
	// counting the number of digits (Method 1)
    int digitcount2(int number) {

        if (number < 0) number *= -1;
        if (number == 0) return 1;
        int count = 0;
        while (number > 0) {
            number /= 10;
            count++;
        }
        return count;
    }
*/  
	// counting the number of digits (Method 2)
  	int digitcount(int number){
        return (int) (Math.log10(number)) + 1;
    }
  
    boolean isEvenDigit(int number){
        return digitcount(number) % 2 == 0;
    }
}
Prabhu Kiran Konda

Leetcode pair chiffres


int findNumbers(int* nums, int numsSize){
        
        int c = 0;
        
        for(int i = 0; i < numsSize; i++){
               
                if(numDigit(nums[i]) % 2 == 0){
                        c++;
                } 
        }

        return c;
}

Inexpensive Iguana

Réponses similaires à “Leetcode pair chiffres”

Questions similaires à “Leetcode pair chiffres”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code