나는 문자열이 "teststring"
있습니다. Ruby에서 처음으로 반복되지 않는 문자를 찾고 싶습니다.
이 Python 코드가 있습니다.
def first_non_repeat_character(teststring)
unique=[]
repeated=[]
for character in teststring:
if character in unique:
unique.remove(character)
repeated.append(character)
else:
if not character in repeated:
unique.append(character)
if len(unique):
return unique[0]
else:
return false
def first_non_repeat_character(string)
string.chars.find { |character| string.count(character) == 1 }
end
first_non_repeat_character('teststring') # => "e"
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다