-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern_13.py
More file actions
63 lines (49 loc) · 839 Bytes
/
pattern_13.py
File metadata and controls
63 lines (49 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
n = 5
____*
___*_*
__*___*
_*_____*
*_______*
_*_____*
__*___*
___*_*
____*
2nd last row : (n - 2) th
spaces(n - 2) = 2(n - 2) - 1 = 2n - 5
# upper triangle (n)
# spaces: n - i - 1
# star: 1
# spaces: 2i - 1
# star: 1 except for first
# lower triangle (n - 1)
# spaces: i + 1
# star: 1
# spaces: k - 2i
# star: 1 except for last
"""
"""
Time Complexity: O(n^2)
Space Complexity: O(1)
"""
n = int(input())
# upper triangle
for i in range(n):
# spaces
print(end=' ' * (n - 1 - i))
# star
print(end='*')
# spaces
print(end=' ' * (2 * i - 1))
# star
print('' if i == 0 else '*')
# lower triangle
for i in range(n - 1):
# spaces
print(end=' ' * (i + 1))
# star
print(end='*')
# spaces
print(end=' ' * (2 * n - 5 - 2 * i))
# star
print('' if i == n - 2 else '*')