LeetCode之Single Number
生活随笔
收集整理的這篇文章主要介紹了
LeetCode之Single Number
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、題目
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?
Subscribe to see which companies asked this question.
2、代碼實現(xiàn)
代碼實現(xiàn)1
public static int singleNumber1(int nums[]) {if (nums == null) return 0;int length = nums.length;int count = 0;for (int i = 0; i < length ; i++) {for (int j = 0; j < length; j++) {if (i != j) {if (nums[i] == nums[j]) continue;else {count++; }}}if (count == length - 1)return nums[i];count = 0;} return 0;總結(jié)
以上是生活随笔為你收集整理的LeetCode之Single Number的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode之Longest Com
- 下一篇: LeetCode之Find the Di