From 2346c90e1a1a71a278a42463c842e6bd47f2ce63 Mon Sep 17 00:00:00 2001 From: Sunil Shrestha <116238476+Xtha-Sunil@users.noreply.github.com> Date: Wed, 30 Oct 2024 20:34:30 +0545 Subject: [PATCH] Added solution for single number iii --- C++/single-number-iii.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 C++/single-number-iii.cpp diff --git a/C++/single-number-iii.cpp b/C++/single-number-iii.cpp new file mode 100644 index 0000000..c8e798e --- /dev/null +++ b/C++/single-number-iii.cpp @@ -0,0 +1,22 @@ +class Solution { +public: + vector singleNumber(vector& nums) { + long long allxor; + for(int x:nums){ + allxor^=x; + } + + int mask = allxor &(-allxor); + int a=0; + int b=0; + for(int x:nums){ + if(mask&x){ + a^=x; + } + else{ + b^=x; + } + } + return {a,b}; + } +}; \ No newline at end of file