File tree 3 files changed +43
-0
lines changed
Algorithms/Easy/1295_FindNumbersWithEvenNumberOfDigits
3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ int countDigit (int n) {
4
+ return floor (log10 (n) + 1 );
5
+ }
6
+
7
+ int findNumbers (vector<int >& nums) {
8
+ int ans = 0 , n = nums.size ();
9
+ for (int i = 0 ; i < n; i++) {
10
+ if (!(countDigit (nums[i]) & 1 ))
11
+ ans++;
12
+ }
13
+ return ans;
14
+ }
15
+ };
Original file line number Diff line number Diff line change
1
+ public class Solution {
2
+ public int CountDigit ( int n ) {
3
+ return ( int ) Math . Floor ( Math . Log10 ( n ) + 1 ) ;
4
+ }
5
+
6
+ public int FindNumbers ( int [ ] nums ) {
7
+ int ans = 0 , n = nums . Length ;
8
+ for ( int i = 0 ; i < n ; i ++ ) {
9
+ if ( CountDigit ( nums [ i ] ) % 2 == 0 )
10
+ ans ++ ;
11
+ }
12
+ return ans ;
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int countDigit (int n ) {
3
+ return (int )Math .floor (Math .log10 (n ) + 1 );
4
+ }
5
+
6
+ public int findNumbers (int [] nums ) {
7
+ int ans = 0 , n = nums .length ;
8
+ for (int i = 0 ; i < n ; i ++) {
9
+ if (countDigit (nums [i ]) % 2 == 0 )
10
+ ans ++;
11
+ }
12
+ return ans ;
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments