题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#include <stdio.h> #include <string.h> int main(){ char str[1002]; scanf("%s", str); int len = strlen(str); int arr[26] = {0}; for(int j = 0; j < len; j++){ arr[str[j] - 'a']++; } int flag = 0; for(int k = 0; k < len; k++){ if(arr[str[k] - 'a'] == 1){ printf("%c", str[k]); return 0; } } printf("-1"); return 0; }