Skip to content

Instantly share code, notes, and snippets.

@tyler-austin
Created June 21, 2017 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyler-austin/2c1a9314f3112b99ada69e881842fb55 to your computer and use it in GitHub Desktop.
Save tyler-austin/2c1a9314f3112b99ada69e881842fb55 to your computer and use it in GitHub Desktop.
Code Fights - differentSymbolsNaive

Given a string, find the number of different characters in it.

Example

For s = "cabca", the output should be
differentSymbolsNaive(s) = 3.

There are 3 different characters a, b and c.

Input/Output

  • [time limit] 4000ms (py3)

  • [input] string s

    A string of lowercase latin letters.

    Guaranteed constraints:

    3 ≤ s.length ≤ 15.
    
  • [output] integer

def different_symbols_naive(s: str):
return len(set(list(s)))
import unittest
from different_symbols_naive import different_symbols_naive
class TestDifferentSymbolsNaive(unittest.TestCase):
def test_1(self):
input_string = 'cabca'
solution = 3
result = different_symbols_naive(input_string)
self.assertEqual(result, solution)
def test_2(self):
input_string = 'aba'
solution = 2
result = different_symbols_naive(input_string)
self.assertEqual(result, solution)
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment