一个int型数组里面所有数都出现两次,只有两个数出现一次。找出这两个数。
Solution:
public void findTwoUniqueNumbers(int[] A) { int x = 0; for(int i=0; i<A.length; i++) { x ^= A[i]; } int lsb = x & -x; int a = 0, b = 0; for(int i=0; i<A.length; i++) { if((A[i]&lsb) == lsb) { a ^= A[i]; } else { b ^= A[i]; } } System.out.println("a="+a + ", b="+b); }
相关推荐
iOS_多媒体_强大的动画_序列帧和无限循环动画_9Cheetah-serial-repeating
Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
删除单链表中的重复项 并学习如何创建fun函数 - 副本
421 | [Maximum XOR of Two Numbers in an Array](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/) | [C++](./C++/maximum-xor-of-two-numbers-in-an-array.cpp) [Python](./Python/...
Lesson 31 - Creating a class for an object type Lesson 32 - Working with your own object types Lesson 33 - Customizing classes Lesson 34 - Capstone project: card game UNIT 8 - USING LIBRARIES TO ...
A simple program that generates non repeating numbers at random in certain ranges.
php'content' => [ 'type' => 'repeating' , 'settings' => [ 'field_groups' => [ [ 'name' => 'Heading' , 'slug' => 'heading' , 'elements' => [ [ 'label' => 'Main Heading' , 'slug' => 'main_heading' , '...
最长子串无重复字符没有重复字符的最长子串的长度( )
3-longest-substring-without-repeating-characters 7 cargo run --bin 7-reverse-integer 9 cargo run --bin 9-palindrome-number 13 cargo run --bin 13-roman-to-integer 14 cargo run --bin 14-longest-common-...
ckanext-eaw_schema 要求 例如,您可能要在这里提及该扩展程序使用的CKAN版本。 安装 要安装ckanext-eaw_schema: 激活您的CKAN虚拟环境,例如: ....将ckanext-eaw_schema Python软件包安装到您的虚拟环境中: ...
导出重复数据外部模块 用户手册 该EM的最终用户文档为 它有什么作用? REDCap中对数据报告和导出的本机支持在重复表单数据时效果不佳。 以下是要考虑的报告方案: 报告中的所有数据均属于单例(非重复)形式。...
./0003-longest-substring-without-repeating-characters.cpp ./0004-median-of-two-sorted-arrays.cpp ./0005-longest-palindromic-substring.cpp ./0006-zigzag-conversion.cpp ./0007-reverse-integer.cpp ./0008...
Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. s = leetcode return 0. s = loveleetcode, return 2. 二、题解 方法一:map map 对...
leetcode题库 LeetCode-Web 初始化 前端库依赖 下载,并将jquery-3.x.x.min.js移动到static目录下。 下载,并将semantic.min.js、semantic.min.css、components和themes...longest-substring-without-repeating-charac
non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) ...
CSS repeating-linear-gradient 方法 创造一个可重复的渐变。它接受和普通线性渐变相同的属性值并且表现也一致。 但它会自动在延伸的方向上重复 color stops。每段起始和结束的 color stop 之间是一个基本的...