一、题目1
二、思路
三、代码
public class T1295 {
public static void main(String[] args) {
System.out.println( findNumbers( new int[]{12,345,2,6,7896} ) ); //2
}
public static int findNumbers(int[] nums) {
int result = 0;
// for ( int i = 0; i < nums.length; i++ ){
if ( (nums[i]+"").length()%2 == 0 )
result++;
//
// result += (nums[i]+"").length()%2 == 0 ? 1:0;
// }
for ( int i : nums){
result += (i+"").length()%2 == 0 ? 1:0;
}
return result;
}
}
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/find-numbers-with-even-number-of-digits
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 ↩︎