Determine if a string has all Unique Characters | C # program to illustrate String with unique characters without using any data structure ; Assuming string can have characters a - z this has 32 bits set to 0 ; if that bit is already set in checker , return false ; otherwise update and continue by setting that bit in the checker ; no duplicates encountered , return true ; Driver Code
using System ; class GFG { public virtual bool uniqueCharacters ( string str ) { int checker = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { int bitAtIndex = str [ i ] - ' a ' ; if ( ( checker & ( 1 << bitAtIndex ) ) > 0 ) { return false ; } checker = checker | ( 1 << bitAtIndex ) ; } return true ; } public static void Main ( string [ ] args ) { GFG obj = new GFG ( ) ; string input = " geekforgeeks " ; if ( obj . uniqueCharacters ( input ) ) { Console . WriteLine ( " The ▁ String ▁ " + input + " ▁ has ▁ all ▁ unique ▁ characters " ) ; } else { Console . WriteLine ( " The ▁ String ▁ " + input + " ▁ has ▁ duplicate ▁ characters " ) ; } } }