File tree Expand file tree Collapse file tree 3 files changed +47
-4
lines changed
Expand file tree Collapse file tree 3 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 1+ '''
2+ [문제] : https://school.programmers.co.kr/learn/courses/30/lessons/12924#
3+ [Flow]
4+ 연속된 자연수의 조합-> two point
5+ 0. 초기화
6+ start == end-1 = 0
7+ while end <= len(words) and start < end
8+ 1. sum(words[start,end]) < target
9+ -> end += 1
10+ 2. sum(words[start,end]) == target
11+ -> count += 1
12+ -> start += 1
13+ -> end = start +1
14+
15+ 3. sum(words[start,end]) > 0
16+ -> 2와 동일
17+
18+ '''
19+ def solution (n ):
20+ answer = 1 # 본인= target
21+ start = 0 ; end = start + 1 ;
22+ answer_li = []
23+ half = round (n // 2 ) + 2
24+ field = range (1 ,half ) # 반올림
25+ field = list (field )
26+
27+ while n > 2 and end <= len (field ) and start < end and start < len (field ): #
28+ current = sum (field [start : end ])
29+ if current < n :
30+ end += 1
31+ else : # currnet >= n
32+ if current == n :
33+ answer += 1
34+ answer_li .append ([start , end ])
35+ start += 1
36+ end = start + 1
37+ return answer
Original file line number Diff line number Diff line change 44
55words = input ()
66window_size = words .count ("a" ) # 1. a의 개수 = sliding window 크기
7- result = 999999999
7+ result = 99999999
88
99# 원형 문자열
1010words += words [0 :window_size - 1 ]
1111# 2. 최대한 a 가 연속해 있는 idx 범위 찾기
1212for start in range (len (words ) - (window_size - 1 )):
1313 result = min (result , words [start : start + window_size ].count ("b" ))
1414
15- print (result )
15+ print (result )
16+
Original file line number Diff line number Diff line change 11"""
2+ 문제 : # 1806부분합
23https://www.acmicpc.net/problem/1806
4+
5+ 해설 :
6+ https://aia1235.tistory.com/46
7+
38"""
49import sys
510N ,S = map (int , sys .stdin .readline ().split ())
1722 end += 1
1823 if end < N :
1924 partial_sum += arr [end ]
20- else : # 수열 끝 -> 조건 충족 x
25+ else : #반복문 끝
2126 break
2227
2328
24- if min_length == 100000 :
29+ if min_length == 100000 : # 수열 끝 -> 조건 충족 x
2530 print (0 )
2631else :
2732 print (min_length )
You can’t perform that action at this time.
0 commit comments