题目链接:
https://www.nowcoder.com/questionTerminal/e896d0f82f1246a3aa7b232ce38029d4
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
boolean flag = false;
for(int i = 0; i < str.length(); i++){
if(str.indexOf(str.charAt(i)) == str.lastIndexOf(str.charAt(i))){
System.out.println(str.charAt(i));
flag = true;
break;
}
}
if(!flag){
System.out.println(-1);
}
}
}
class Solution {
public int maxProduct(String[] words) {
int ans = 0;
for(int i= 0; i < words.length; i++){
String word1 = words[i];
for(int j = i + 1; j < words.length; j++){
String word2 = words[j];
if(!hasSameChar(word1, word2)){
ans = Math.max(ans, word1.length() * word2.length());
}
}
}
return ans;
}
public boolean hasSameChar(String word1, String word2){
for(char c : word1.toCharArray()){
if(word2.indexOf(c) != - 1) return true;
}
return false;
}
}