2020. 3. 21. 17:21ㆍPython/CodeSignal Algorithm
33. Given an array of equal-length strings, you'd like to know if it's possible to rearrange the order of the elements in such a way that each consecutive pair of strings differ by exactly one character. Return true if it's possible, and false if not.
Note: You're only rearranging the order of the strings, not the order of the letters within the strings!
[Example]
|
[Solution]
#<My Code>
def stringsRearrangement(inputArray):
#<Best Code>
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):
s = inputString
for i in range(len(s)):
if(s[i].isdigit()): return s[i]
#<Best Code>
def firstDigit(inputString):
for i in inputString:
if i.isdigit():
return i
'Python > CodeSignal Algorithm' 카테고리의 다른 글
[Python] CodeSignal 문제 풀이 (37~39) (0) | 2020.03.31 |
---|---|
[Python] CodeSignal 문제 풀이 (34~36) (0) | 2020.03.31 |
[Python] CodeSignal 문제 풀이 (31~33) (0) | 2020.03.12 |
[Python] CodeSignal 문제 풀이 (28~30) (0) | 2020.03.12 |
[Python] CodeSignal 문제 풀이 (25~27) (0) | 2020.03.12 |