【LeetCode】136. Single Number 解题小结
生活随笔
收集整理的這篇文章主要介紹了
【LeetCode】136. Single Number 解题小结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目:
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?
這題目的要求不僅是要求是線性時間,希望也不會使用額外的內存,那么也就是你無法運用其他的數據結構。也是參考了其他人的答案。對于位操作的特性還有待進一步挖掘。
class Solution { public:int singleNumber(vector<int>& nums) {int num = 0;for (int i = 0; i < nums.size(); ++i){num ^= nums[i];}return num;} };
?
轉載于:https://www.cnblogs.com/Doctengineer/p/5824385.html
總結
以上是生活随笔為你收集整理的【LeetCode】136. Single Number 解题小结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 有关卖车的微信网名
- 下一篇: 爱丽丝梦游仙境中的亚伯索伦的配音是?是不