Leetcode - Flatten a Multilevel Doubly Linked List
Leetcode - Squares of a Sorted Array

Leetcode - Find Numbers with Even Number of Digits

violet posted @ Jul 14, 2020 01:50:08 AM in 算法 with tags Algorithm Golang array , 353 阅读

https://leetcode.com/problems/find-numbers-with-even-number-of-digits/

Given an array nums of integers, return how many of them contain an even number of digits.

 

Example 1:

Input: nums = [12,345,2,6,7896]
Output: 2
Explanation: 
12 contains 2 digits (even number of digits). 
345 contains 3 digits (odd number of digits). 
2 contains 1 digit (odd number of digits). 
6 contains 1 digit (odd number of digits). 
7896 contains 4 digits (even number of digits). 
Therefore only 12 and 7896 contain an even number of digits.
func findNumbers(nums []int) int {
    result := 0
    for _, n := range nums {
        if isEven(n) {
            result++
        }
    }
    return result
}

func isEven(num int) bool {
    result := 0
    for num > 0 {
        num /= 10
        result++
    }
    return result % 2 == 0
}
BSNL Broadband Plans 说:
Feb 02, 2023 09:43:24 PM

ISP provides unlimited calls to any network round the clock in all the BSNL broadband plans over fiber and DSL networks, and Here we update the latest BSNL broadband unlimited plans daily across India as and when the update released for home and business tariff, BSNL Broadband Plans So check each plan in detail to opt for best tariff. BSNL broadband plans over DSL and Bharat Fiber technologies are available, we categorize each plan and provide the updated information of all the circles with new plans and tariff.

pavzi.com 说:
Jan 25, 2024 11:10:59 PM

Pavzi.com is a startup by passionate webmasters and bloggers who have a passion for providing engaging content that is accurate, interesting, and worthy to read. pavzi.com We are more like a web community where you can find different information, resources, and topics on day-to-day incidents or news. We provide you with the finest web content on every topic possible with the help of the editorial and content team.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter