Data Structure Array: Find the two numbers with odd occurrences in an unsorted array
http://www.geeksforgeeks.org/find-the-two-numbers-with-odd-occurences-in-an-unsorted-array/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; void printtwoodd(int arr[], int n) {
int x = arr[];
for (int i = ; i < n; i++) x ^= arr[i];
x &= ~(x-);
int ans1, ans2;
ans1 = ans2 = ;
for (int i = ; i < n; i++) {
if (arr[i] & x) ans1 ^= arr[i];
else ans2 ^= arr[i];
}
cout << ans1 << " " << ans2 << endl;
} int main() {
int arr[] = {, , , , , , , };
printtwoodd(arr, );
return ;
}
Data Structure Array: Find the two numbers with odd occurrences in an unsorted array的更多相关文章
- [Algorithm] Heap data structure and heap sort algorithm
Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...
- [LeetCode] 170. Two Sum III - Data structure design 两数之和之三 - 数据结构设计
Design and implement a TwoSum class. It should support the following operations:add and find. add - ...
- [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计
Design and implement a TwoSum class. It should support the following operations:add and find. add - ...
- ✡ leetcode 170. Two Sum III - Data structure design 设计two sum模式 --------- java
Design and implement a TwoSum class. It should support the following operations: add and find. add - ...
- LeetCode Two Sum III - Data structure design
原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a ...
- LeetCode 笔记27 Two Sum III - Data structure design
Design and implement a TwoSum class. It should support the following operations: add and find. add - ...
- hdu 4217 Data Structure? 树状数组求第K小
Data Structure? Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- leetcode3 Two Sum III – Data structure design
Question: Design and implement a TwoSum class. It should support the following operations: add and f ...
- 170. Two Sum III - Data structure design
题目: Design and implement a TwoSum class. It should support the following operations: add and find. a ...
随机推荐
- 捕获php请求内容
通过将phpinfo()打印到文件实现 <?php echo str_pad('', 1024);//使缓冲区溢出 ob_start();//打开缓冲区 phpinfo(); $string = ...
- ajax个人学习笔记
1. function createXHR(){ if(typeof XMLHttpRequest != 'undefined'){ return new XMLHttpRequest(); }els ...
- angularjs事件传递$on、$emit和$broadcast
如何在作用域之间通信呢? 1.创建一个单例服务,然后通过这个服务处理所有子作用域的通信. 2.通过作用域中的事件处理通信.但是这种方法有一些限制:例如,你并不能广泛的将事件传播到所有监控的作用域中.你 ...
- 禁止"Windows Media Player Network Sharing Service"服务自动启动
开始 -> 运行 -> gpedit.msc -> 计算机配置 -> 管理模板 -> Windows 组件 -> Windows Media Player -> ...
- Swift_1_基本数据类型
import Foundation println("Hello, World!"); var v1 = 1; var v2 = 2; println(" v1 is \ ...
- 过年啦!小B高兴的不行了,她收到了很多红包,可以实现好多的愿望呢。小B可是对商店货架上心仪的货物红眼好久了,只因囊中羞涩作罢,这次她可是要大大的shopping一番。小B想去购物时,总是习惯性的把要买的东西列在一个购买清单上,每个物品单独列一行(即便要买多个某种物品),这次也不例外。
include "stdafx.h" #include<iostream> #include<vector> #include <algorithm& ...
- 《Python基础教程》第20章学习笔记
python实现:https://github.com/captainwong/instant_markup c++实现:https://github.com/captainwong/instant_ ...
- ThinkPHP3.1URL分发BUG修正
请先留意以下PHP脚本 PHP脚本A(http://127.0.0.1:8110/test.php): $url = 'http://127.0.0.1:8110/demo.php'; //curl请 ...
- LeakCanary Android 和 Java 内存泄露检测
说起内存泄漏还是挺让人头疼的,而且不是每个手机都会发生的情况,往往又不易察觉,那么今天我们就来介绍下LeakCanary这个工具 githup:https://github.com/square/le ...
- zookeeper 客户端
http://blog.csdn.net/lzy_lizhiyang/article/details/48518731 http://blueyan.iteye.com/blog/2298276 ht ...