-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
59-9kyo-hwang #210
59-9kyo-hwang #210
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def solution(storey):
answer = 0
flag = False
storey = str(storey)
for y in range(len(storey)-1,-1,-1):
x = int(str(storey)[y])
if(flag == True):
x += 1
flag = False
if(y==0):
if x>=6: answer += 10-x+1
else: answer += x
return answer
if(x>=6):
answer += (10 - x)
flag = True
elif(x<=4): answer += x
else:
if y>=1:
if int(storey[y-1])>=5:
answer += (10 - x)
flag = True
else: answer += x
μ«μ΄νλ μ νμ λ¬Έμ ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5μΌ λ, 5μ¦κ°μν¬μ§ 5λ₯Ό λΉΌλ²λ¦΄μ§ κ²½κ³μ μ°Ύλλ° ν€λ§Έλ€μ γ
γ
γ
γ
μνμ₯μμ μ€μ λ‘ λ§λλ©΄ λ±κ³¨ μ€μΉν λ―ν©λλ€..γ
def solution(storey):
answer = 0
carry = False
numbers = list(str(storey))[::-1]
n = len(numbers)
for i in range(len(numbers)):
now = int(numbers[i]) + carry
answer += now
carry = False
if now > 5:
answer -= (-10 + now*2)
carry = True
continue
if now == 5 and i != n-1:
next = int(numbers[i+1])
if next >= 5 :
carry = True
continue
if carry:
answer += 1
return answer
π λ¬Έμ λ§ν¬
λ§λ²μ μλ¦¬λ² μ΄ν°
βοΈ μμλ μκ°
1μκ°
β¨ μλ μ½λ
1. μ€λͺ
νμ¬ λμ μλ¦¬λ² μ΄ν°λ$1 \le storey \le 100,000,000$ ) μΈ΅μ μλ€. $-1, +1, -10, +10, -100, +100, ...$ κ³Ό κ°μ΄ μ λκ°μ΄ $10^c$ ($c \ge 0$ ) ννμΈ μ μλ€μ΄ μ ν λ²νΌ μλ¦¬λ² μ΄ν°λ₯Ό ν΅ν΄ 0μΈ΅μΌλ‘ κ°κ³ μ νλ€.
storey
(ν΄λΉ λ²νΌμ λλ₯΄λ©΄ νμ¬ μΈ΅ μμ λ²νΌμ μ ν μλ κ°μ λν μΈ΅μΌλ‘ μ΄λνκ² λλλ°, μλ¦¬λ² μ΄ν°κ° μμΉν΄ μλ μΈ΅κ³Ό λ²νΌμ κ°μ λν κ²°κ³Όκ° 0λ³΄λ€ μμΌλ©΄ μλ¦¬λ² μ΄ν°λ μμ§μ΄μ§ μλλ€.
μλ¦¬λ² μ΄ν°λ₯Ό μμ§μ΄κΈ° μν΄μ λ²νΌ ν λ²λΉ λ§λ²μ λ ν κ°λ₯Ό μ¬μ©νλ€.
μ΄μ κ°μ΄ μ΄λ€ μΈ΅μμ μλ¦¬λ² μ΄ν°λ₯Ό νκ³ 0μΈ΅μΌλ‘ λ΄λ €κ°λλ° νμν λ§λ²μ λμ μ΅μ κ°μλ₯Ό μκ³ μ νλ€.
νμ¬ μΈ΅μ λνλ΄λ μ μ
storey
κ° μ£Όμ΄μ‘μ λ, 0μΈ΅μΌλ‘ κ°κΈ° μν΄ νμν λ§λ²μ λμ μ΅μκ°μ return νλλ‘ solution ν¨μλ₯Ό μμ±νλΌ.2. νμ΄
μ²μμ λ¬Έμ λ₯Ό λ± λ³΄μλ§μ 1λ‘ λ§λ€κΈ° λ¬Έμ λ μ¨λ°κΌμ§ κ±°μ λΉμ·ν΄ 보μ¬μ 거리 ν μ΄λΈκ³Ό queueλ₯Ό μ΄μ©ν BFSλ‘ νλ €κ³ νμΌλ...
BFS μλ μ½λ
κ±°μ λͺ¨λ ν μΌμμ μκ° μ΄κ³Όκ° λ°μνλ€.
1λ‘ λ§λ€κΈ°λ 무쑰건 μ«μκ° κ°μνλ κ²λ°μ μκΈ° λλ¬Έμ μΌμ΄μ€λ₯Ό κ·κ²°μν¬ μ μμκ³ , μ¨λ°κΌμ§μ μ«μ λ²μκ° μ’κΈ° λλ¬Έμ λ²μ΄λλ μΌμ΄μ€λ₯Ό λ§μ΄ κ±°λ₯Ό μ μμμ§λ§ μ΄ λ¬Έμ λ μλμλ€...
κ²°κ΅ μ½μ§ μ’ νλ€κ° λ€ μ§μ°κ³ μ§λ¬Έ κ²μνμ νμΈν΄λ³΄κ³ λμ κ°μ μ‘μλ€.
ν΅μ¬μ "λμ리 μ«μλ₯Ό νμΈν΄μ λνκΈ°/λΉΌκΈ° μννκΈ°"μ΄λ€.
μμλ₯Ό 보면 μ μ μλ―, λ€μ 0μ΄ λΆμ΄μλ κ²½μ°λ μ¬μ€μ λΌκ³ μκ°ν΄λ 무방νλ€λ κ²μ μ μ μλ€.
μ£Όμν΄μ λ΄μΌν μ μ μ«μκ° "5"μΈ κ²½μ°μΈλ°
μλ₯Ό λ€μ΄, 65λ₯Ό 0μΌλ‘ λ§λ λ€κ³ νλ©΄
μ΄λ κ² 5μμ +1/-1 νλ κ±°μ λ°λΌ νμκ° λ¬λΌμ§λλ°, +1 νλ κ²μ΄ λ νμκ° μ μμ μ μ μλ€. μ΄λ μ μλ¦¬κ° "6"μΈ κ²μ λ³΄κ³ +1μ νκΈ° λλ¬Έμ΄λ€.
μ΄ κ·μΉμ μ£Όμν΄μ μ½λλ₯Ό μμ±νλ©΄ λλ€.
μ½λλ κ°λ¨νλ€. μμμ μκΈ°ν μΌμ΄μ€λ₯Ό κ·Έλλ‘ κ΅¬νν κ²μ΄λ€.
λ μλ¦Ώμλ₯Ό κ·Έλκ·Έλ νμΈν΄μ 5 μ΄κ³Ό / 5 λ―Έλ§ / 5 3κ°μ§ κ²½μ°λ‘ λλ λͺ«μ 보μ ν λ€ λ²νΌ λλ₯Έ νμλ₯Ό λν΄μ£Όλ©΄ λλ€.
π μλ‘κ² μκ²λ λ΄μ©
μ½κ° μ‘°μ΄μ€ν± λ¬Έμ λ λΉμ·ν κ² κ°κΈ°λ νλ€...