[TIL] 0520 코딩테스트 Seek.com

IT/TIL(Today I Learnt)|2022. 5. 21. 01:18

Today I Learnt

0520:

Seek.com 코딩 테스트는
codeility로 4문제 한 문제당 30분씩 해서 2시간 동안 봤다.

생각보다 쉬웠는데 생각보다 못했다 ㅋㅋㅋ 장난하나... 쳐 맞아야지 진짜

1. 주어진 스트링에서 첫 번째 문자가 upper case or lower case
2. 주어진 두 개의 숫자를 곱해서 나온 binary represent value has how many 1 inside?
3. Stupid debugging question.
4. get maximum number by deleting one digit
https://leetcode.com/problems/contains-duplicate/

Contains Duplicate - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

https://skilllx.com/function-that-returns-maximum-possible-value-given-an-integer-n/

Function that returns Maximum Possible Value, Given an integer N - Skilllx

Function that return for given an integer, maximum possible value obtainable by deleting one '5' digit from the decimal representation of N

skilllx.com

아 진짜 멍청하게 이걸 틀리네 :
그래서 다시 풂.

def solution(N):

    S= str(N)
    input_array = list(S)
    indexNums=[]
    results =[]
    # print(input_array)

    if(input_array[0] != "-"):
        for i in range(len(input_array)):
            if input_array[i]=="5":
                indexNums.append(i)
        for j in range(len(indexNums)):

            indexNum =indexNums[j]
            result = input_array.copy()
            result[indexNum] = "a"
            results.append(result)
        finalAnswer =[]
        for x in results:
            x.remove("a")
            finalAnswer.append(int("".join(x)))
        return max(finalAnswer)
    else:
        for i in range(1, len(input_array)):
            if input_array[i] == "5":
                indexNums.append(i)
        for j in range(len(indexNums)):
            indexNum = indexNums[j]
            result = input_array.copy()
            result[indexNum] = "a"
            results.append(result)
        finalAnswer = []
        for x in results:
            x.remove("a")
            finalAnswer.append(int("".join(x)))
        return max(finalAnswer)

print(solution(N))
print(solution(-5859))
print(solution(5000))
print(solution(-5000))

일단 시간은 필요없고 맞추는거에 집중하라고햇으니깐 이렇게 풀긴햇는데 뭐 더 좋은 방법이있었지만
이렇게 풀려고했는데 못풀엇음... 화나내진짜

반응형

'IT > TIL(Today I Learnt)' 카테고리의 다른 글

[TIL]  (0) 2022.05.25
[TIL] 0523 PyScript ?  (0) 2022.05.23
[TIL] 0519  (2) 2022.05.20
[TIL] 0518  (0) 2022.05.19
[TIL] 0517 코딩 테스트  (0) 2022.05.18

댓글()