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 }
thank you so much sir
⭐⭐Don't forget to subscribe to our channel ⭐⭐
Subscribers : 505
Thank you for your support!
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
}
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 '$';
}