π
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| import random | |
| import pytest | |
| nums = list(random.randint(1, 100) for _ in range(100)) | |
| @pytest.mark.benchmark( | |
| min_rounds=10000000, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| # λ¬Έμ : 3λ²μ§Έ ν° μ | |
| - λ°°μ΄μμ 3λ²μ¬λ‘ ν° μλ₯Ό μ°Ύμμ λ°ννλλ‘ νμ. | |
| - λ§μ½ 3λ²μ§Έλ‘ ν° μκ° μλ€λ©΄ κ°μ₯ ν° μλ₯Ό λ°ννλ©΄ λλ€. μλ₯Ό λ€μ΄μ λ°°μ΄μ [1, 2, 3] μ΄ μλ€λ©΄ 1μ λ°ννκ³ | |
| 3λ²μ§Έκ° μλ λ°°μ΄ [2, 3] μ΄λΌλ©΄ 3μ λ°ννλ©΄ λλ€. | |
| ### μμ΄λμ΄ (μ λ ¬) | |
| 1. λ°°μ΄μ μμμΌλ‘ μ λ ¬νλ€. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| # λ¬Έμ : λΆμ‘±ν κΈμ‘ κ³μ°νκΈ° | |
| - λμ΄κΈ°κ΅¬μ μλ μ΄μ©λ£λ price μμ΄λ€. | |
| - λμ΄κΈ°κ΅¬λ₯Ό N λ²μ§Έ μ΄μ©νλ€λ©΄ μλ μ΄μ©λ£μ Nλ°°λ₯Ό λ°λ ν¨λν°κ° μλ€. | |
| - μλ₯Ό λ€μ΄μ, μ²μ μ΄μ©λ£κ° 100μ μ΄μλ€λ©΄, 2λ²μ§Έλ 200μ 3λ²μ§Έλ 300μμ΄λ€. | |
| -> λμ΄κΈ°κ΅¬λ₯Ό {count} λ² νκ² λλ©΄, νμ¬ μμ μ΄ κ°μ§κ³ μλ κΈμ‘μμ μΌλ§κ° λͺ¨μλΌλμ§λ₯Ό λ°ν νλ ν¨μλ₯Ό μμ±νλΌ | |
| -> λ¨ κΈμ‘μ΄ λΆμ‘±νμ§ μμΌλ©΄ 0μ λ°ννλΌ. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| λ¬Έμ 6.6 νΈλ¦¬ κ²½λ‘μ ν© | |
| λ Έλμ μ μν λ°μ΄ν°κ° μλ μ΄μ§ νΈλ¦¬κ° μ λ ₯μΌλ‘ μ£Όμ΄μ§λ€. | |
| κ° κ²½λ‘μ μλ λ Έλμ λ°μ΄ν° ν©μ΄ νΉμ κ°μ΄ λλ κ²½μ°κ° λͺ κ°μΈμ§ νμΈνλΌ. | |
| κΌ λ£¨νΈ λ Έλμμ μμν νμλ μμΌλ©°, μμμ λΆλͺ¨ λ Έλμμ μμ λ Έλ μͺ½μΌλ‘ μ΄λνμ¬ ν©μ λ§λ€μ΄ | |
| λκ°μΌ νλ€. μμ λ Έλμμ μλ‘ μ¬λΌκ°λ κ²½μ°λ μλ€. | |
| ### μ ν μ¬ν |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| # κΉμ΄ μ°μ νμ, λλΉ μ°μ νμ, κ·Έλ¦¬κ³ μ΄μ§ ν | |
| ### κΉμ΄ μ°μ νμ (Depth-First Search) | |
| κΉμ΄ μ°μ νμμ ν€μλλ 'μ€ν (Stack)' μ΄λ€. | |
| μ μμ μμ μ¬μ©ν νΈλ¦¬μ κΉμ΄ μ°μ νμμΌλ‘ λ Έλλ₯Ό λ°©λ¬Έμ ν΄λ³΄μ. | |
| ### λλΉ μ°μ νμ (Breadth-First Search) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| μ΄μ§ νΈλ¦¬λ₯Ό ꡬννμ¬λΌ. | |
| """ | |
| class Node: | |
| def __init__(self, data): | |
| self.left = None | |
| self.right = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| λ¬Έμ : λ²λΈ μ λ ¬μ ꡬννμμ€. | |
| """ | |
| from typing import List | |
| def bubble_sort(arr: List[int]): | |
| n = len(arr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| λ¬Έμ : λ°°μ΄μ λ λΆλΆμ§ν©μ μ΅μ μ°¨μ΄ λ§λ€κΈ° | |
| λ°°μ΄μ λ λΆλΆμ§ν©μ λ§λ€κ³ κ° λΆλΆμ§ν©μ ν© μ°¨μ΄κ° μ΅μκ° λλ κ°μ λ°ννλΌ | |
| μλ₯Ό λ€μ΄μ [3, 2, 7, 4, 1]μ΄ μ£Όμ΄μ§λ©΄ λΆλΆμ§ν©μ ν© μ°¨μ΄κ° μ΅μκ° λκ² νλ €λ©΄, | |
| νλλ [1, 7]μ΄ λκ³ , λ€λ₯Έ νλλ [2, 3, 4]κ° λμμ λ κ° λΆλΆμ§ν©μ ν©μ 8κ³Ό 9κ° λμ΄μ μ°¨μ΄κ° 1μ΄ λλ€. | |
| μ΄λ 1μ λ°ννλλ‘ κ΅¬ννλ κ²μ΄λ€. | |
| """ | |
| import sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| λ¬Έμ 4.4.3 λμ κ΅ν | |
| κ°κ²μ κ°μ, 물건μ μ¬κ³ 물건 κ°μ μ§λΆνκ³ λ¨μ μλμ κ±°μ¬λ‘ μ£Όλ κ³Όμ μ μ½λ©νλλ° | |
| κ°μ₯ μ μ κ°μμ λμ μΌλ‘ λ°νν΄μΌνλ κ²μ΄ λ¬Έμ μ΄λ€. μλμΌλ‘ κ±°μ¬λ¬ μ£Όλ λμ μ κ°μ | |
| λ°°μ΄λ‘ μ λ ₯ λ°λλ°, μλ₯Ό λ€μ΄ [1, 2, 5] μ΄κ³ κ±°μ¬λ¬μ€μΌ νλ λμ΄ 11μ΄λΌλ©΄ [5, 5, 1] λ‘ 3κ°λ₯Ό | |
| κ±°μ¬λ¬ μ£Όλ κ²μ΄ κ°μ₯ μ μ λμ μ κ°μλ‘ λ°νν κ²μ΄λ€. | |
| """ | |
| import sys | |
| from typing import List |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| λ¬Έμ 4.4.2 λͺ¨λ λ¬Έμμ΄ μΉν | |
| μ λ ₯μΌλ‘ μ£Όμ΄μ§ λ¬Έμμ΄μ κ°λ₯ν μΉνμ λͺ¨λ μΆλ ₯ν΄λ³΄λ λ¬Έμ μ΄λ€. | |
| μλ₯Ό λ€μ΄, μ λ ₯λ λ¬Έμμ΄μ΄ 'abc' λΌλ©΄ κ²°κ³Όλ ["abc", "acb", "bac", "cab", "cba"] κ° λμ΄μΌ νλ€. | |
| κ° λ¬Έμκ° λμ΄λ λͺ¨λ μμΉμ μ‘°ν©μ λ§λ€μ΄λΌ. | |
| """ | |
| from typing import List |