Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Ch 1.Arrays And Strings/1.Is Unique/1. Is_unique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <vector>
#include <iostream>
#include <bitset>
#include <map>
#include <algorithm> // for sort()

using namespace std;
Expand Down Expand Up @@ -49,6 +50,20 @@ bool isUniqueChars_noDS( string str) {
return noRepeat;
}

bool is_unique(string str){
map<char, int> character_counts;

int ctr = 0;
for (char c: str){
if (character_counts[c]==1){
return false;
}
character_counts[c]=1;
}

return true;
}

int main(){
vector<string> words = {"abcde", "hello", "apple", "kite", "padle"};
for (auto word : words)
Expand Down