思路分析

对一个数求log10运算再向上取整可以基本确定其位数,但是要考虑10这样会产生整数的情况。

代码实现

  1. class Solution {
  2. public int findNumbers(int[] nums) {
  3. int ans = 0;
  4. for (int i : nums){
  5. if (Math.ceil(Math.log10(i + 1)) % 2 == 0){
  6. ans++;
  7. }
  8. }
  9. return ans;
  10. }
  11. }