| 12345678910111213141516171819202122 |
- # Implement an algorithm to determine if a string has all unique characters.
- # What if you can not use additional data structures?
- import pytest
- def isUnique(input):
- input_len = len(input)
- sub_string = {}
- for i in range(input_len):
- if input[i] in sub_string:
- return False
- else:
- sub_string[input[i]] = True
- return True
- def test_unique():
- input1 = 'asdfghjkl'
- input2 = 'aaaawwwwf'
- assert isUnique(input1) == True
- assert isUnique(input2) == False
- pytest.main()
|