题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#import <Foundation/Foundation.h>
int main(int argc, char* argv[]) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
char str[1000];
gets(str);
int len = strlen(str);
int a[1000] = {0};
for (int i = 0; i < len; i++) {
a[str[i]]++;
}
for (int i = 0; i < len; i++) {
if (a[str[i]] == 1) {
printf("%c\n", str[i]);
break;
}
if (i == len - 1) {
printf("-1\n");
break;
}
}
[pool drain];
return 0;
}
基恩士成长空间 421人发布
查看30道真题和解析