[Python] CodeSignal 문제 풀이 (34~36)
2020. 3. 31. 21:15ㆍPython/CodeSignal Algorithm
34. Given array of integers, remove each kth element from it.
[Example]
For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and k = 3, the output should be extractEachKth(inputArray, k) = [1, 2, 4, 5, 7, 8, 10]. |
[Solution]
#<My Code>
def extractEachKth(inputArray, k):
a = inputArray
del a[k-1::k]
return a
#<Best Code>
def extractEachKth(inputArray, k):
del inputArray[k-1::k]
return inputArray
35. Find the leftmost digit that occurs in a given string.
[Example]
|
[Solution]
#<My Code>
def firstDigit(inputString):
for i in inputString:
if i.isdigit(): return i
36. Given a string, find the number of different characters in it.
[Example]
For s = "cabca", the output should be There are 3 different characters a, b and c. |
[Solution]
#<My Code>
def differentSymbolsNaive(s):
return len(set(s))
'Python > CodeSignal Algorithm' 카테고리의 다른 글
[Python] CodeSignal 문제 풀이 (40~42) (0) | 2020.03.31 |
---|---|
[Python] CodeSignal 문제 풀이 (37~39) (0) | 2020.03.31 |
[Python] CodeSignal 문제 풀이 (33~35) (0) | 2020.03.21 |
[Python] CodeSignal 문제 풀이 (31~33) (0) | 2020.03.12 |
[Python] CodeSignal 문제 풀이 (28~30) (0) | 2020.03.12 |