https://www.hackerrank.com/challenges/lonely-integer

 def main():
n = int(raw_input())
s = dict()
a = 0 arr = map(int,raw_input().strip().split())
for _ in range(n):
num = arr[_]
if not s.get(num):
s.update({num:1})
else:
a = s.get(num)
a += 1
s.update({num:a}) for i in s:
if s.get(i) % 2 != 0:
print i
break main()

学习  

  怎样利用新的数据结构“字典”来解决问题

//另一个方式:过滤

 #!/usr/bin/py
def lonelyinteger(a):
answer = 0
answer = reduce(lambda x,y: x^y, a)
return answer
if __name__ == '__main__':
a = input()
b = map(int, raw_input().strip().split(" "))
print lonelyinteger(b)

学习 

  http://jeffxie.blog.51cto.com/1365360/328207 三个过滤函数

  神奇的xor运算

    异或运算有两个特性:

    1、一个数异或本身恒等于0,如5^5恒等于0;

    2、一个数异或0恒等于本身,如5^0恒等于5。

    所以比如  print 0 ^ 0 ^ 1 ^ 2 ^ 1

    根据结合律,所有相同的都消除为0,而0和最后孤单的值,成为孤单值本身

Lonely Integer的更多相关文章

  1. 【HackerRank】Lonely Integer

    There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the ...

  2. [LeetCode] Lonely Pixel II 孤独的像素之二

    Given a picture consisting of black and white pixels, and a positive integer N, find the number of b ...

  3. [LeetCode] 533. Lonely Pixel II 孤独的像素 II

    Given a picture consisting of black and white pixels, and a positive integer N, find the number of b ...

  4. LeetCode 7. Reverse Integer

    Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have you ...

  5. Integer.parseInt 引发的血案

    Integer.parseInt 处理一个空字符串, 结果出错了, 程序没有注意到,搞了很久, 引发了血案啊!! 最后,终于 观察到了, 最后的部分: Caused by: java.lang.NoC ...

  6. 由一个多线程共享Integer类变量问题引起的。。。

    最近看到一个多线程面试题,有三个线程分别打印A.B.C,请用多线程编程实现,在屏幕上循环打印10次ABCABC- 看到这个题目,首先想到的是解决方法是定义一个Integer类对象,初始化为0,由3个线 ...

  7. [LeetCode] Integer Replacement 整数替换

    Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...

  8. [LeetCode] Integer Break 整数拆分

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  9. [LeetCode] Integer to English Words 整数转为英文单词

    Convert a non-negative integer to its english words representation. Given input is guaranteed to be ...

随机推荐

  1. C程序设计语言练习题1-2

    练习1-2 做个实验,当printf函数的参数字符串中包含\c(其中c是上面的转义字符串序列中未曾列出的某一个字符)时,观察一下会出现什么情况. 代码如下: #include <stdio.h& ...

  2. Codeforces 519E A and B and Lecture Rooms

    http://codeforces.com/contest/519/problem/E 题意: 给出一棵树和m次询问,每次询问给出两个点,求出到这两个点距离相等的点的个数. 思路: lca...然后直 ...

  3. JavaScript对象基础知识

    1.对象所包含的元素一组包含数据的属性.如人的名字.书的价格和手机型号等.允许对属性中所包含的数据进行操作的方法. 2.引用对象的途径一个对象真正地被使用,可以采用以下几种方式.引用Javascrip ...

  4. BZOJ1106: [POI2007]立方体大作战tet

    1106: [POI2007]立方体大作战tet Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 419  Solved: 302[Submit][St ...

  5. Java中一些常用的代码

    总结一下最近程序中用到的代码吧,大部分不是自己写的,放到这里,备份一下,以后忘记了来看一下: //正则表达式验证手机号 public static void phoneTest(String phon ...

  6. NOI2013 UOJ122 向量内积

    神题...... 还是大神讲得比较清晰~orz http://dffxtz.logdown.com/posts/197950-noi2013-vector-inner-product 启发题:poj3 ...

  7. 【POJ2136】Vertical Histogram(简单模拟)

    比较简单,按照样例模拟就好!~ #include <iostream> #include <cstdlib> #include <cstdio> #include ...

  8. hdu 5391 Zball in Tina Town(打表找规律)

    问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候, ...

  9. uiautomatorviewer 识别android微信元素报错

    org.xml.sax.SAXParseException; systemId: file:/C:/Users/xxxxxxxxx/AppData/Local/Temp/uiautomatorview ...

  10. python3-day4(装饰器)

    一.基本 第一波 #### def foo():     print 'foo'   foo     #表示是函数 foo()   #表示执行foo函数   #### 第二波 #### def foo ...