leetcode 136-Single Number

来源:互联网 发布:楚楚街聊天是什么软件 编辑:程序博客网 时间:2024/06/06 21:11

难度:easy

Given an array of integers, every element appears twice except for one. Find that single one.

Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

思路:1. 这种找出list里面唯一一个重复次数与其他都不同的element的题特别适合用dictionary来做。

           2. 将list里面的每个element变成dictionary里的key,element在list里面出现的次数则为value,最后找到value=1时对应的key即可。

           3. dictionary操作:


          

原创粉丝点击