String Find First Non Repeating Character Return S Index Doesn T Exist Return 1 C S Leetco Q37161595

String, find the first non-repeating character in it and returnit’s index. If it doesn’t exist, return -1.(c++)

s = “leetcode”

return 0.

s = “loveleetcode”,

return 2.


Answer


#include <string>#include <iostream>using namespace std;int non_repeated_index(string s) { int count; for(int i = 0; i < s.length(); ++i) { count = 0; for(int j = 0; j < s.length(); ++j) { if(s[i] == s[j]) {

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.