Description:

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

找出只出现一次的数。

public class Solution {
public int singleNumber(int[] nums) {
Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for(int i=0; i<nums.length; i++) {
if(map.containsKey(nums[i])) {
int times = map.get(nums[i]);
map.put(nums[i], times+1);
}
else
map.put(nums[i], 1);
}
Set<Integer> set = map.keySet();
for(int i : set) {
if(map.get(i) == 1) {
return i;
}
}
return 0; }
}

LeetCode——Single Number的更多相关文章

  1. [LeetCode] Single Number III 单独的数字之三

    Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...

  2. [LeetCode] Single Number II 单独的数字之二

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

  3. [LeetCode] Single Number 单独的数字

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

  4. LeetCode Single Number I / II / III

    [1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个 ...

  5. LeetCode:Single Number II

    题目地址:here 题目大意:一个整数数组中,只有一个数出现一次,其余数都出现3次,在O(n)时间,O(1)空间内找到这个出现一次的数 对于”只有一个数出现一次,其余数出现2次“的情况,很简单,只要把 ...

  6. LeetCode Single Number III

    原题链接在这里:https://leetcode.com/problems/single-number-iii/ 题目: Given an array of numbers nums, in whic ...

  7. [leetcode]Single Number II @ Python

    原题地址:http://oj.leetcode.com/problems/single-number-ii/ 题意:Given an array of integers, every element ...

  8. LeetCode——Single Number II(找出数组中只出现一次的数2)

    问题: Given an array of integers, every element appears three times except for one. Find that single o ...

  9. LeetCode: Single Number I && II

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

  10. [LeetCode] Single Number III ( a New Questions Added today)

    Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...

随机推荐

  1. 7-zip 压缩算法及C SDK使用

    pdf版本下载:http://files.cnblogs.com/davad/7-zip_and_SDK.pdf 1. 介绍 官方网址:中文:http://sparanoid.com/lab/7z/ ...

  2. HTML文档的经常使用标记

    一.HTML文档中经常使用的标记有文字标记.段落标记.列表标记.超链接标记.图像标记.表格标记.框架标记和多媒体标记,以下对这些经常使用标记进行介绍: 1.文字标记:文字是网页重要的组成部分之中的一个 ...

  3. PixelMatorPro快捷键大全(osx)

    Keyboard Shortcuts Navigate an image   Zoom in Command-Plus (+) Zoom out Command-Minus (-) Zoom to f ...

  4. 又一个错误" Fatal error: Call to undefined function myabp_print_screenshot_all() "

    xxx ( ! ) Fatal error: Call to undefined function myabp_print_screenshot_all() in D:\wamp\www\wp-con ...

  5. jQuery EasyUI教程之datagrid应用

    一.利用jQuery EasyUI的DataGrid创建CRUD应用 对网页应用程序来说,正确采集和管理数据通常很有必要,DataGrid的CRUD功能允许我们创建页面来列表显示和编辑数据库记录.本教 ...

  6. Jquery 技术小结

    前记: 现在项目中经常要用到JS去操作一些事,对整个团队开发来说,JS的书写规范和正确对开发具有较大的帮助.在一个团队中常常会发生JS书写的不统一性和游览器不兼容性等情况发生.我觉的最好的方法就是有一 ...

  7. selenium测试(Java)--下拉框(二十一)

    例子: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...

  8. Java的四种引用类型之弱引用

    先说结论: 首先,Java中有四种引用类型:强引用.软引用.弱引用.虚引用.-- 在 Java 1.2 中添加的,见 package java.lang.ref; . 其次,这几个概念是与垃圾回收有关 ...

  9. Erlang的Web库和框架

    ChicagoBoss,Nitrogen ,Zotontic,BeepBeep,ErlyWeb,Erlang Boss. 转自:http://bbs.chinaunix.net/thread-3764 ...

  10. c++ 类型定义

    1. typedef map<int, CString> UDT_MAP_INT_CSTRING; UDT_MAP_INT_CSTRING enumMap;