题目链接

  题目要求:

  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?

  这道题属于比较简单的,程序如下:

 class Solution {
public:
int singleNumber(vector<int>& nums) {
unordered_map<int, int> hashMap;
int sz = nums.size();
for(int i = ; i < sz; i++)
hashMap[nums[i]]++; unordered_map<int, int>::iterator itr = hashMap.begin();
for(; itr != hashMap.end(); itr++)
{
if(itr->second == )
return itr->first;
} return INT_MIN;
}
};

LeetCode之“散列表”:Single Number的更多相关文章

  1. LeetCode(137) Single Number II

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

  2. LeetCode之“散列表”:Two Sum && 3Sum && 3Sum Closest && 4Sum

    1. Two Sum 题目链接 题目要求: Given an array of integers, find two numbers such that they add up to a specif ...

  3. 【LeetCode OJ 136】Single Number

    题目链接:https://leetcode.com/problems/single-number/ 题目:Given an array of integers, every element appea ...

  4. leetcode文章137称号-Single Number II

    #include<stdio.h> #include<stdlib.h> int singleNumber(int* nums, int numsSize) { int cou ...

  5. [LeetCode&Python] Problem 136. Single Number

    Given a non-empty array of integers, every element appears twice except for one. Find that single on ...

  6. LeetCode(136) Single Number

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

  7. LeetCode之“散列表”:Isomorphic Strings

    题目链接 题目要求: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic i ...

  8. LeetCode之“散列表”:Contains Duplicate && Contains Duplicate II

     1. Contains Duplicate 题目链接 题目要求: Given an array of integers, find if the array contains any duplica ...

  9. LeetCode之“散列表”:Valid Sudoku

    题目链接 题目要求: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku boar ...

随机推荐

  1. PHP学习(3)—在HTML中嵌入PHP

    我们以一个提交订单和显示订单信息的例子为学习PHP的开始.这个例子包含两个文件.一个提交订单的html文件:orderform.html,一个显示订单信息的php文件:processorder.php ...

  2. tomcat启动批处理——startup.bat

    从文件命名上看就知道这是一个启动批处理,这个批处理的主要功能就是为了找到另一个批处理catalina.bat,并且执行catalina.bat. 一开始就用if "%OS%" == ...

  3. GDB调试工具入门

    从windows转到linux下已经有一段时间了,每次刷算法题碰到问题需要调试的时候,就分分钟想关机,切换到windows上调试.于是,花了一点时间来搜索一下linux下常见的调试工具,这不搜不知道, ...

  4. UNIX网络编程——原始套接字的魔力【上】

    基于原始套接字编程 在开发面向连接的TCP和面向无连接的UDP程序时,我们所关心的核心问题在于数据收发层面,数据的传输特性由TCP或UDP来保证: 也就是说,对于TCP或UDP的程序开发,焦点在Dat ...

  5. Scipy教程 - 优化和拟合库scipy.optimize

    http://blog.csdn.net/pipisorry/article/details/51106570 最优化函数库Optimization 优化是找到最小值或等式的数值解的问题.scipy. ...

  6. java造成内存泄露原因

    一.Java内存回收机制  不论哪种语言的内存分配方式,都需要返回所分配内存的真实地址,也就是返回一个指针到内存块的首地址.Java中对象是采用new或者反射的方法创建的,这些对象的创建都是在堆(He ...

  7. maven -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME

    遇到错误:-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME解决办法:在环境变量中设置M2_HO ...

  8. Deep Learning with Torch

    原文地址:https://github.com/soumith/cvpr2015/blob/master/Deep%20Learning%20with%20Torch.ipynb Deep Learn ...

  9. Ubuntu启动eclipse问题

    Ubuntu启动eclipse问题 在Ubuntu安装eclipse后 可以在终端顺利启动eclipse:进入eclipse目录,在终端输入命令 ./eclipse > /dev/null 2& ...

  10. UI设计——最后一根稻草

    WindowsLive提供的本地地图服务看起来挺简单的,但其实非常难用: 跟其他人一样,每当我接触到一个新的地图服务,我做的第一件事总是拿当前的地址去试一试.我在上面输入的是我工作的地方.但是,当我敲 ...