AcWing 772. 只出现一次的字符 - Java
原题链接
中等
作者:
KYCygni
,
2021-03-17 04:19:08
,
所有人可见
,
阅读 359
Java 代码
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
String line = cin.next();
int[] freq = new int[26];
for (int i = 0; i < line.length(); i++)
{
freq [(int)line.charAt(i) - (int)'a'] += 1;
}
boolean found = false;
for (int i = 0; i < line.length(); i++)
{
if (freq [(int)line.charAt(i) - (int)'a'] == 1)
{
found = true;
System.out.println(line.charAt(i));
break;
}
}
if (! found)
System.out.println("no");
}
}
棒