How to determine if a string has all unique characters in C#

1 Answer

0 votes
using System;
 
class Program
{
    static bool count_unique_char(string s) {
        int[] ascii = new int[256];
        int size = s.Length;
      
        for (int i = 0; i < size; i++) {
            ascii[s[i]] += 1;
            if (ascii[s[i]] > 1)
                return false;
        }

        return true;
    }
 
    static void Main() {
        string s = "node.js c#";
 
        Console.Write(count_unique_char(s));
    }
}
 
  
 
  
  
  
  
/*
run:
  
True
  
*/

 



answered May 6, 2022 by avibootz
edited May 7, 2022 by avibootz

Related questions

1 answer 131 views
1 answer 127 views
1 answer 148 views
1 answer 121 views
1 answer 105 views
...