인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

sgyouoy1232025's profile image
sgyouoy1232025

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

5. Sum of numbers

스택으로 풀어봤는데요

Written on

·

245

2

import sys
sys.stdin=open('input.txt', 'rt')

n, m = map(int, input().split())
a = list(map(int, input().split()))

cnt = 0
b = list()

for i in a:
b.append(i)
sum1 = sum(b)
if(sum1==m):
cnt+=1
b.pop(0)
elif(sum1>m):
while(sum(b)>m):
b.pop(0)
if(sum(b)==m):
cnt+=1

print(cnt)

스택으로 풀어봤는데요.
강사님의 알고리즘이 훨씬 더 좋아보이네요
코테 준비 같이 해요! python

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

본인 스스로의 코드를 짜보는 것은 굉장이 중요합니다. 그리고 그 코드와 제가 짠 코드의 효율성을 비교해보고 선택하시면 좋겠습니다.

sgyouoy1232025's profile image
sgyouoy1232025

asked

Ask a question