Notice
Recent Posts
Recent Comments
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Tags more
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐ŸŒฒ์ž๋ผ๋‚˜๋Š”์ฒญ๋…„

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค]์กฐ์ด์Šคํ‹ฑ, python ๋ณธ๋ฌธ

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ’€์ด

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค]์กฐ์ด์Šคํ‹ฑ, python

JihyunLee 2021. 1. 31. 12:14
๋ฐ˜์‘ํ˜•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def solution(name):
    alph = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    max_len = 0
    max_index = -1
    
    for i in range(1,len(name)):
        search = 'A'* i
        index = name.find(search) 
        if index != -1:
            max_index = index
            max_len = i
            
    next_notA = max_index + max_len + 1
    if max_index != -1:
        move = min([len(name)-1, (max_index-1+ (len(name)+(max_index))-next_notA])
    else:
        move = len(name)-1
    
            
        
            
    for character in name:
        index = alph.index(character)
        dist1 = index
        dist2 = len(alph)-index
        
        move += min([dist1, dist2])
        
    return move
cs

์ขŒ์šฐ๋กœ ์›€์ง์—ฌ์•ผํ•˜๋Š” ํšŸ์ˆ˜, ์œ„ ์•„๋ž˜๋กœ ์›€์ง์—ฌ์•ผ ํ•˜๋Š” ํšŸ์ˆ˜๋ฅผ ๋‹ค๋ฅด๊ฒŒ ๊ณ„์‚ฐํ•ด์„œ ๋”ํ•ด์คฌ๋‹ค

๋ฐ˜์‘ํ˜•