📙
python-algorithm
  • 🖋️알고리즘 풀이 저장소
  • 이론
    • BFS & DFS 이론
    • 다익스트라 이론
    • 최소신장트리(크루스칼) 이론
    • 백트래킹 이론
  • 유형
    • 정렬
    • 순열과 조합
    • 탐색
    • 이분 탐색
    • SHA-256
    • 투 포인터
    • 피보나치
    • Z 재귀함수
    • 재귀함수
    • 친구 네트워크
    • 찾기
    • 큐
    • 스택 수열
    • 기하학
    • 트리 순회
    • 고급 탐색
    • BFS & DFS 알고리즘
    • 다익스트라 알고리즘
    • 최소신장트리(크루스칼) 알고리즘
    • 동적 프로그래밍
    • 그리디 알고리즘
    • 백트래킹 알고리즘
  • 기타
    • 베스트셀러
    • 성
    • 키 로거
    • 음계
Powered by GitBook
On this page
  • 백준 2003번 : 수들의 합 2
  • 1. 단순 반복문 풀이
  • 2. 투 포인터 풀이
  1. 유형

투 포인터

#투 포인터

백준 2003번 : 수들의 합 2

1. 단순 반복문 풀이

count, sum=list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))

counting=0
temp=0

for i in range(count):
  temp=0
  for j in range(i, count):
    temp=temp + a[j]
    if(temp==sum):
      counting=counting+1
      break
    elif(temp>sum):
      break

print(counting)

2. 투 포인터 풀이

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

start=0
answer=0
end=0

while start <=end and end<=len(A):
    summ = sum(A[start:end])
    if summ==m:
        answer+=1
    if summ<=m:
        end+=1
    elif summ>m and start<end:
        start+=1

print(answer)
PreviousSHA-256Next피보나치

Last updated 3 years ago