def duplicate_encode(word: str) -> str:
tmp = word.lower()
result = ""
for i in tmp:
if tmp.count(i)==1:
result = result + "("
else:
result = result + ")"
return result
def duplicate_encode(word: str) -> str:
words = []
duplicate_words = []
result = ""
for i in word:
i = i.lower()
if i not in words:
words.append(i)
else:
duplicate_words.append(i)
for i in word:
i = i.lower()
if i not in duplicate_words:
result += "("
else:
result += ")"
return result
assert duplicate_encode("din") == "((("
assert duplicate_encode("Success") == ")())())"
assert duplicate_encode("(( @") == "))(("
def duplicate_encode(word):
start = 0
end = len(word) - 1
while start < len(word) - 1:
for index in range(end, start, -1):
if word[start].lower() == word[index].lower():
word = word.replace(word[start], ')')
word = word.replace(word[index], ')')
start += 1
for index in range(0, len(word)):
if word[index] != ')':
word = word.replace(word[index], "(")
return word
assert duplicate_encode("din") == "((("
assert duplicate_encode("Success") == ")())())"
assert duplicate_encode("(( @") == "))(("
public class DuplicateEncoder {
static String encode(String word){
word = word.toLowerCase();
String result = "";
for (int i = 0; i < word.length(); ++i) {
char c = word.charAt(i);
result += word.lastIndexOf(c) == word.indexOf(c) ? "(" : ")";
}
return result;
}
}