Determine if a string has all Unique Characters | C ++ program to illustrate string with unique characters using brute force technique ; If at any time we encounter 2 same characters , return false ; If no duplicate characters encountered , return true ; driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool uniqueCharacters ( string str ) { for ( int i = 0 ; i < str . length ( ) - 1 ; i ++ ) { for ( int j = i + 1 ; j < str . length ( ) ; j ++ ) { if ( str [ i ] == str [ j ] ) { return false ; } } } return true ; } int main ( ) { string str = " GeeksforGeeks " ; if ( uniqueCharacters ( str ) ) { cout << " The ▁ String ▁ " << str << " ▁ has ▁ all ▁ unique ▁ characters STRNEWLINE " ; } else { cout << " The ▁ String ▁ " << str << " ▁ has ▁ duplicate ▁ characters STRNEWLINE " ; } return 0 ; }