Skip to content

Commit 672904a

Browse files
committed
Find Numbers with Even Number of Digits
1 parent 51333a9 commit 672904a

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

Salve Array Problems.ipynb

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,53 @@
745745
"toLowerCase(\"LOVELY\")"
746746
]
747747
},
748+
{
749+
"cell_type": "code",
750+
"execution_count": 2,
751+
"metadata": {},
752+
"outputs": [
753+
{
754+
"name": "stdout",
755+
"output_type": "stream",
756+
"text": [
757+
"2\n"
758+
]
759+
}
760+
],
761+
"source": [
762+
"\"\"\"\n",
763+
"1295. Find Numbers with Even Number of Digits\n",
764+
"\n",
765+
"Given an array nums of integers, return how many of them contain an even number of digits.\n",
766+
" \n",
767+
"Input: nums = [12,345,2,6,7896]\n",
768+
"Output: 2\n",
769+
"\n",
770+
"Explanation: \n",
771+
"12 contains 2 digits (even number of digits). \n",
772+
"345 contains 3 digits (odd number of digits). \n",
773+
"2 contains 1 digit (odd number of digits). \n",
774+
"6 contains 1 digit (odd number of digits). \n",
775+
"7896 contains 4 digits (even number of digits). \n",
776+
"Therefore only 12 and 7896 contain an even number of digits.\n",
777+
"\n",
778+
"\"\"\"\n",
779+
"from typing import List\n",
780+
"def findNumbers(nums: List[int]) -> int:\n",
781+
" count = 0\n",
782+
" for i in nums:\n",
783+
" digitCount = 0\n",
784+
" temp = i;\n",
785+
" while temp > 0:\n",
786+
" temp = temp // 10\n",
787+
" digitCount +=1\n",
788+
" if digitCount % 2 == 0 :\n",
789+
" count +=1\n",
790+
" return count\n",
791+
"\n",
792+
"print(findNumbers([12,345,2,6,7896]))"
793+
]
794+
},
748795
{
749796
"cell_type": "code",
750797
"execution_count": null,
@@ -769,7 +816,7 @@
769816
"name": "python",
770817
"nbconvert_exporter": "python",
771818
"pygments_lexer": "ipython3",
772-
"version": "3.6.10"
819+
"version": "3.7.4"
773820
}
774821
},
775822
"nbformat": 4,

0 commit comments

Comments
 (0)