Single Number | GFG POTD | 18-10-24 | Easy | 3 ways | GFG Problem of the day | C++ | Java | python
HTML-код
- Опубликовано: 27 ноя 2024
- #geeksforgeeks #problemoftheday #cpp #datastructures #potd #potdgfgtoday #gfg #gfgsolutions #gfgstreek #cpp #python #javascript #java #javaprogramming #datastructures #algorithm #algorithms #pythonprogramming #coding #programming
Geeks for Geeks Problem of the Day(POTD) in C++ | Single Number | Full code Available :👇
GitHub 🔗: UdaySharmaGitHub
Repository Name: GFG-Problems
Informative ℹ️👍
Glad you like it
// Approach -1 using XOR Operation //
int getSingle(vector& arr) {
// code here
int ans = 0;
for(int i:arr) ans^=i;
return ans;
}
// Approach -2 using MAP //
int getSingle(vector& arr) {
// code here
map map;
for(int i:arr) map[i]++;
for(auto i:map) if(i.second&1) return i.first ;
return 0;
}
// Approach - 3 using SET//
int getSingle(vector& arr) {
// code here
set set;
for(int i=0;i