Untitled
unknown
plain_text
a year ago
1.2 kB
9
Indexable
class Solution {
public String answerString(String word, int numFriends) {
int length = word.length() - numFriends + 1;
int idx = 0;
if(numFriends==1){
return word;
}
for(int i=1;i<word.length();i++){
if(Character.compare(word.charAt(idx),word.charAt(i)) == 0){
if(word.substring(idx).compareTo(word.substring(i))<0){
idx = i;
}
}
else if(Character.compare(word.charAt(idx),word.charAt(i)) < 0){
// System.out.println(Character.compare(word.charAt(idx),word.charAt(i)));
idx = i;
}
}
StringBuilder largestString = new StringBuilder("");
// System.out.println(idx);
int s = idx-1;
while(idx < word.length() && length > 0){
largestString.append(word.charAt(idx)+"");
idx++;
length--;
}
int remChars = word.length() - largestString.length();
return largestString.toString();
}
}©leetcodeEditor is loading...
Leave a Comment