Non Repeating Character | GFG POTD 1st Dec 2024 | JAVA | C++

Поделиться
HTML-код
  • Опубликовано: 2 дек 2024

Комментарии • 4

  • @mooginiharika7412
    @mooginiharika7412 День назад

    thank you so much sir

  • @codeCraft9
    @codeCraft9  2 дня назад +1

    ⭐⭐Don't forget to subscribe to our channel ⭐⭐
    Subscribers : 505
    Thank you for your support!

  • @codeCraft9
    @codeCraft9  2 дня назад +1

    C++ Code :
    char nonRepeatingChar(string &s) {
    // Your code here
    vector arr(26, 0); // Array to store frequency of each character
    // Count the frequency of each character
    for (char c : s) {
    ++arr[c - 'a'];
    }
    // Find the first character with frequency 1
    for (char c : s) {
    if (arr[c - 'a'] == 1) {
    return c;
    }
    }
    return '$'; // Return '$' if no unique character is found
    }

  • @codeCraft9
    @codeCraft9  2 дня назад +1

    JAVA Code :
    static char nonRepeatingChar(String s) {
    // Your code here
    int[] arr = new int[26];
    for(char c : s.toCharArray()){
    ++arr[c - 'a'];
    }

    for(char c : s.toCharArray()){
    if(arr[c - 'a'] == 1){
    return c;
    }
    }
    return '$';
    }