|
745 | 745 | "toLowerCase(\"LOVELY\")"
|
746 | 746 | ]
|
747 | 747 | },
|
| 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 | + }, |
748 | 795 | {
|
749 | 796 | "cell_type": "code",
|
750 | 797 | "execution_count": null,
|
|
769 | 816 | "name": "python",
|
770 | 817 | "nbconvert_exporter": "python",
|
771 | 818 | "pygments_lexer": "ipython3",
|
772 |
| - "version": "3.6.10" |
| 819 | + "version": "3.7.4" |
773 | 820 | }
|
774 | 821 | },
|
775 | 822 | "nbformat": 4,
|
|
0 commit comments