- 浏览: 19312 次
- 性别:
- 来自: 北京
文章分类
最新评论
题目描述: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?
1 自己的代码
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
1 自己的代码
import java.util.Arrays; public class SingleNumber { public int singleNumber(int[] A) { Arrays.sort(A); int result = A[0]; for(int i = 0; i < A.length; i = i + 2){ if(i == A.length - 1){ result = A[i]; break; } if(A[i] == A[i+1]) continue; else{ result = A[i]; break; } } return result; } }
发表评论
-
Java中String与StringBuffer的区别
2014-10-29 21:07 302String和StringBuffer的区别,网上资料可以说 ... -
String to Integer (atoi)
2014-10-29 17:13 401题目描述 Implement atoi to convert ... -
Implement strStr()
2014-10-28 15:17 289题目描述 Implement strStr(). Retu ... -
Valid Palindrome
2014-10-23 10:32 425题目描述 Given a string, determine ... -
ZigZag Conversion
2014-10-22 19:51 346题目描述 The string "PAYPALIS ... -
Add Binary
2014-10-22 19:43 305题目描述 Given two binary strings, ... -
Longest Common Prefix
2014-10-22 19:44 333题目描述 Write a function to find t ... -
Count and Say
2014-10-22 19:44 348题目描述 The count-and-say sequence ... -
Valid Sudoku
2014-10-21 10:22 358题目描述 Determine if a Sudoku is v ... -
Valid Parentheses
2014-10-21 09:41 327题目描述 Given a string containing ... -
Palindrome Number
2014-10-21 09:41 349题目描述 Determine whether an integ ... -
Length of Last Word
2014-10-21 09:41 359题目描述 Given a string s consists ... -
Minimum Depth of Binary Tree
2014-10-21 09:41 310题目描述 Given a binary tree, find ... -
Remove Nth Node From End of List
2014-10-20 16:36 259题目描述 Given a linked list, remov ... -
Path Sum
2014-10-20 15:37 299题目描述 Given a binary tree and a ... -
Binary Tree Level Order Traversal II
2014-10-20 11:17 236题目描述 Given a binary tree, retur ... -
Binary Tree Level Order Traversal
2014-10-20 11:03 293题目描述 Given a binary tree, retur ... -
Pascal's Triangle II
2014-10-20 10:07 262题目描述 Given an index k, return t ... -
Pascal's Triangle
2014-10-19 12:24 322题目描述 Given numRows, generate th ... -
Plus One
2014-10-19 11:51 340题目描述 Given a non-negative numbe ...
相关推荐
给喜欢算法的同学准备的Single Number调试用demo。
扩展二:给定一个包含n个整数的数组,有一个整数x出现b次,一个整数y出现c次,其他所有的数均出现a次,其中b和c均不是a的倍数,找出x和y。中每一位二进制位1出
Given a specified total t and a list of n integers, find all distinct sums using numbers from the list that add up ... and a single number counts as a sum.) Your job is to solve this problem in general.
Single Number III Power of Two Missing Number Maximum Product of Word Lengths Bitwise AND of Numbers Range Power of Three Rectangle Area 数论 Happy Number Ugly Number Ugly Number II Super Ugly Number ...
The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by ...
A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting ...
260 | [Single Number III](https://leetcode.com/problems/single-number-iii/) | [C++](./C++/single-number-iii.cpp) [Python](./Python/single-number-iii.py) | _O(n)_ | _O(1)_ | Medium || 268| [Missing ...
Number(落单的数) 、 / Medium Single Number II(落单的数 II) 、 Medium Single Number III(落单的数 III) Medium Hash Function(哈希函数) Easy Space Replacement(空格替换) Easy Insert Interval Easy Two ...
Single Number #150 Evaluate Reverse Polish Notation #169 Majority Element #171 Excel Sheet Column Number #217 Contains Duplicate #226 Invert Binary Tree #237 Delete Node in a Linked List #238 Product ...
for i=1 to session("singlenumber")直到next是选择singlenumber(代表某科目的单选题数量)个单选题。 下面的代码实现了从数据库中随机不重复的选题: set rs=server.createobject("adodb.recordset") sql="select ...
for i=1 to session("singlenumber")直到next是选择singlenumber(代表某科目的单选题数量)个单选题。 下面的代码实现了从数据库中随机不重复的选题: set rs=server.createobject("adodb.recordset") sql="select ...
137. 只出现一次的数字 II使用hashMap来存储每个数字出现的次数public int singleNumber(int[] nums) {题解参考:h
各种SingleNumber变种 LinkListCycle I II 其他变种 编程之美 Preorder Traversal Inorder Traver sal postorder 非递归 不用栈! 字符串常用操作 字符串 各种转换 Pow(x,n) 优化 Permutations (交换 取子集两种方式...
只出现一次的数字 题目 给定一个非空整数数组,除了某个元素只出现一次之外,其余每个元素均出现两次。找出那个只出现了一次的元素。... def singleNumber(self, nums: List[int]) -> int: a = 0 for i in n
示例 2:输出:[-1,0]示例 3:输出:[1,0]vector<int> singleNumber(vector<int>& nums) {//先对所有数字
Single Number #0167 - Two Sum - Input Array is sorted #0189 - Rotate Array #0217 - Contains Duplicate #0242 - Valid Anagram #0243 - Shortest Word Distance #0246 - Strobogrammatic Number #0263 -
SINGLE NUMBER 2 HAPPY NUMBER 3 MAXIMUM SUBARRAY 4 Move Zeroes 5 Best Time to Buy and Sell Stock II 6 GROUP ANAGRAMS 7 COUNTING ELEMENTS 日 问题描述 问题和解决方案链接 Git 解决方案页面 8 Middle of the ...
示例 1:输入: [2,2,3,2]输出: 3示例 2:输入: [0,1,0,1,0,1,99]输出: 99int singleNumber(vector<in
dna匹配 leetcode leetcode刷题--C++ ...Number 异或 Copy List with Random Pointer 单链表 map Max Points on a Line 斜率 map, int> Fraction to Recurring Decimal map long long 正负号 Repeated DNA S
// Mobile No can be a single number, list or csv string var mobileNo = "XXXXXXXXXX" ; var mobileNo = [ "XXXXXXXXXX" , "XXXXXXXXXX" , "XXXXXXXXXX" ] ; var mobileNo = "XXXXXXXXXX,XXXXXXXXXX,XXXXXXXXXX" ...