{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Number 448" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/) " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from typing import List\n", "\n", "class Solution:\n", " def findDisappearedNumbers(self, nums: List[int]) -> List[int]:\n", " \"\"\"\n", " \n", " \"\"\"\n", " max_num = len(nums)\n", " desired_dict = {i:0 for i in range(1,max_num+1)}\n", " for i in nums:\n", " desired_dict[i] = desired_dict[i]+1\n", " return [i for i in desired_dict.keys() if desired_dict[i]==0]\n", "\n", "a = Solution()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[5, 6]\n", "[2]\n" ] } ], "source": [ "print(a.findDisappearedNumbers([4,3,2,7,8,2,3,1]))\n", "print(a.findDisappearedNumbers([1,1]))" ] } ], "metadata": { "interpreter": { "hash": "033d5ea8e9748582193a6d8f975af35153e280c1f566336ac6ff582d76ae2a04" }, "kernelspec": { "display_name": "Python 3.6.8 64-bit", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }