Skip to content

Commit 5279a98

Browse files
Add files via upload
1 parent 5a908ea commit 5279a98

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

Day7/DividedIntoNumberArray.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# 15. 나누어 떨어지는 숫자 배열
2+
3+
def solution(arr, divisor):
4+
answer = []
5+
6+
for i in arr:
7+
if i % divisor == 0:
8+
answer.append(i)
9+
else:
10+
continue
11+
12+
if not answer:
13+
answer.append(-1)
14+
15+
answer.sort()
16+
return answer
17+
18+
arr_1 = [5, 9, 7, 10]
19+
arr_2 = [2, 36, 1, 3]
20+
arr_3 = [3, 2, 6]
21+
22+
divisor_1 = 5
23+
divisor_2 = 1
24+
divisor_3 = 10
25+
26+
print(solution(arr_1, divisor_1))
27+
print(solution(arr_2, divisor_2))
28+
print(solution(arr_3, divisor_3))
29+
30+
def solution_best(arr, divisor):
31+
answer = sorted([n for n in arr if n % divisor == 0]) or [-1]
32+
33+
return answer
34+
35+
# print(solution_best(arr_1, divisor_1))
36+
# print(solution_best(arr_2, divisor_2))
37+
# print(solution_best(arr_3, divisor_3))

Day7/NoSameNumber.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# 11. 같은 숫자는 싫어
2+
3+
# 완전 탐색 ... 잘못 생각함
4+
def solution(arr):
5+
answer = []
6+
7+
answer.append(arr[0])
8+
for i in range(1, len(arr)):
9+
if arr[i] != arr[i - 1]:
10+
answer.append(arr[i])
11+
return answer
12+
13+
arr_1 = [1, 1, 3, 3, 0, 1, 1]
14+
arr_2 = [4, 4, 4, 3, 3]
15+
16+
print(solution(arr_1))
17+
print(solution(arr_2))
18+
19+
def solution_best(arr):
20+
answer = arr[:1]
21+
22+
for value in arr:
23+
if answer[-1] == value:
24+
continue
25+
answer.append(value)
26+
return answer
27+
28+
# print(solution_best(arr_1))
29+
# print(solution_best(arr_2))
30+
31+
# pop을 하면 안 됨, 개수가 많아서
32+
# def solution_error(arr):
33+
# answer = []
34+
#
35+
# # 배열 맨 앞의 값
36+
# first = arr.pop(0)
37+
# answer.append(first)
38+
#
39+
# for i in arr:
40+
# if i == first and i != answer[-1]:
41+
# answer.append(i)
42+
# elif i == first and i == answer[-1]:
43+
# continue
44+
# elif i != first and i not in answer:
45+
# answer.append(i)
46+
# elif i != first and i != answer[-1]:
47+
# answer.append(i)
48+
#
49+
# first = arr.pop(0)
50+
#
51+
# return answer
52+
53+
# print(solution_error(arr_1))
54+
# print(solution_error(arr_2))
55+
56+
57+

0 commit comments

Comments
 (0)