class Solution { public: //Function to find the first non-repeating character in a string. char nonrepeatingCharacter(string S) { int chars=256; int n=S.size(); int arr[chars]; fill(arr,arr+chars,0); for(int i=0;i<n;i++) { arr[S[i]]++; } for(int i=0;i<256;i++) { if(arr[S[i]]==1) { return (char)S[i]; } } return '$'; //Your code here } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter