// Using HaspMap or HashTable class Solution { public: int count(struct Node* head, int key) { // add your code here map map; while(head){ map[head->data]++; head = head->next; } return map[key]; } };
// Using Set class Solution { public: int count(struct Node* head, int key) { // add your code here set set; int count = 0 ; while(head){ if(set.find(key) != set.end()){ count++; set.erase(key); } set.insert(head->data); head = head->next; } if(set.find(key) != set.end()){ count++; set.erase(key); } return count ;
// Using Counting class Solution { public: int count(struct Node* head, int key) { // add your code here int count = 0; while(head){ if(head->data == key )count++; head = head->next; } return count; } };
// Using HaspMap or HashTable
class Solution {
public:
int count(struct Node* head, int key) {
// add your code here
map map;
while(head){
map[head->data]++;
head = head->next;
}
return map[key];
}
};
// Using Set
class Solution {
public:
int count(struct Node* head, int key) {
// add your code here
set set;
int count = 0 ;
while(head){
if(set.find(key) != set.end()){
count++;
set.erase(key);
}
set.insert(head->data);
head = head->next;
}
if(set.find(key) != set.end()){
count++;
set.erase(key);
}
return count ;
}
};
// Using Counting
class Solution {
public:
int count(struct Node* head, int key) {
// add your code here
int count = 0;
while(head){
if(head->data == key )count++;
head = head->next;
}
return count;
}
};