Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 오라클
- Algorithm
- sql
- csharp
- 알고리즘
- linux
- 파이썬
- Oracle VM VirtualBox
- dbeaver
- putty
- 리눅스
- HTML
- C#
- 파이썬 전처리
- 파이썬 데이터프레임
- it 용어
- MariaDB
- python algorithm
- 데이터베이스
- 파이썬 알고리즘
- Oracle
- 리눅스 명령어
- it용어
- RFP
- Python DataFrame
- Python 라이브러리
- 코딩테스트
- PYTHON
- VirtualBox
- tibero
Archives
- Today
- Total
오경석의 개발노트
Python 알고리즘_1부터 n까지의 합 구하기 본문
# algorithm_1, 계산복잡도 : O(n)
def sum_num(n):
result = 0
for i in range(n + 1):
result += i
return result
# sum_num_recursion_algorithm, 계산복잡도 : O(n)
def sum_num_recursion(n):
if n < 0:
return print('Please enter only positive numbers')
elif n == 0:
return 0
return n + sum_num_recursion(n - 1)
# algorithm_2, 계산복잡도 : O(1)
def sum_num2(n):
return (n + 1) * (n / 2)'알고리즘 > Python 알고리즘' 카테고리의 다른 글
| Python 알고리즘_리스트 최솟값 구하기 (0) | 2022.11.14 |
|---|---|
| Python 알고리즘_리스트 최댓값 구하기 (0) | 2022.11.14 |
| Python 알고리즘_리스트 최댓값의 위치 구하기 (0) | 2022.11.14 |
| Python 알고리즘_1부터 n까지 연속한 숫자의 제곱의 합 (0) | 2022.11.13 |
| Python 알고리즘_절댓값 구하기 (0) | 2022.11.09 |
Comments