Article

Python

  • [파이썬 기초] 알고리즘 - 재귀, 하노이의 탑

    [파이썬 기초] 알고리즘 - 재귀, 하노이의 탑

    🔍 재귀 알고리즘이란? - 나 자신을 다시 호출하는 알고리즘 1) 재귀 알고리즘 def recusion(num): if num > 0: print("*" * num) return recusion(num-1) else: return 0 recusion(10) ----------------------------- ********** ********* ******** ******* ****** ***** **** *** ** * 2) 팩토리얼 def factorial(num): if num > 0: return num * factorial(num-1) else: return 1 print(f'factorial(4) : {factorial(4)}') ----------------------------------..

  • [파이썬 기초] 알고리즘 - 최빈값, 근사값, 평균

    [파이썬 기초] 알고리즘 - 최빈값, 근사값, 평균

    🗝 최빈값 - 빈도 수가 가장 많은 데이터 - 최대값 알고리즘을 이용하여 배열을 새로 만들고, 값이 나올 때마다 각 인덱스에 +1 class MaxAl: def __init__(self,arr): self.arr = arr self.max = 0 self.maxNumIdx = 0 def setMax(self): self.max = self.arr[0] self.maxIdx = 0 for i, n in enumerate(self.arr): if self.max < n: self.max = n self.maxIdx = i def getMax(self): return self.max def getMaxIdx(self): return self.maxIdx import random as rd nums = [rd...

  • [파이썬 기초] 알고리즘 - 최대값, 최소값

    [파이썬 기초] 알고리즘 - 최대값, 최소값

    🔍 알고리즘 사용 이유 - 해당API가 존재하지만, 작동원리를 알아보기 위함. 🗝 최대값 - 자료 구조에서 가장 큰 값을 찾는다. import random as rd class MaxAl: def __init__(self, array): self.arr = array self.maxNum = 0 def getMax(self): self.maxNum = self.arr[0] for i in self.arr: if self.maxNum < i: self.maxNum = i return self.maxNum array = rd.sample(range(1,100), 10) print(array) maxInt = MaxAl(array) result = maxInt.getMax() print(f'max = {re..

Math & Statistics

  • [기초수학] 순열과 조합

    [기초수학] 순열과 조합

    🎯 순열 - n개에서 r개를 택하여 나열하는 경우의 수(순서 상관 있음) $_{n}\mathrm{P}_{r}= \frac{n!}{(n-r)!}$ (단, $0

  • [기초수학] 수열

    [기초수학] 수열

    🔍 수열이란? - 규칙성을 가지고 나열되어 있는 수들 1. 등차 수열 - 연속된 두 항의 차이가 일정한 수열 $a_n = a_1 + (n-1)d$ $S_n = \frac {n(a_1+a_n)}{2}$ 2. 등비 수열 - 연속된 두 항의 비가 일정한 수열 $a_n = a_1 * r^{(n-1)}$ $S_n = a_1*\frac {1-r^n}{1-r}$ [함수] 등차수열, 등비수열 계산기 🔍 문제 함수를 이용하여 등차수열, 등비수열 계산기 만들기 🗝 사용함수 등차수열 공식, 등비수열 공식 🖥 실행 (등차수열) def arithSq(a, d, n): an = 0; sum = 0 for i in range(1,n+1): if i == 1: an = a.. designingdata.tistory.com 3. 계차..

  • [통계] 시계열 분석

    [통계] 시계열 분석

    ⏱​시계열 분석(time series analysis) - 시계열(시간의 흐름에 따라 기록된 것) 자료(data)를 분석하고 여러 변수들간의 인과관계를 분석 1. 시계열 데이터 - 시계열 데이터는 시간을 기준으로 관측된 데이터 - 보통 일 → 주 → 월 → 분기 → 년 또는 Hour 등 시간의 경과에 따라 관측 ex) GDP, 주가, 거래액, 매출액, 승인금액 등을 시간에 흐름에 따라 정의한 데이터 1) 연속시계열 - 자료가 연속적으로 생성 - 대부분의 데이터 형태가 연속형이나 이산형 정의하여 분석 2) 이산형 시계열 - 일정 시차(간격)를 두고 관측되는 형태의 데이터 - 대부분 이산형 데이터를 분석 2. 시계열 데이터의 목적 - 예측 : 금융시장 예측, 수요 예측등 미래의 특정 시점에 대한 관심의 대상..

LeetCode

  • [LeetCode] Find All Numbers Disappeared in an Array

    [LeetCode] Find All Numbers Disappeared in an Array

    🔍 문제 Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Input: nums = [4,3,2,7,8,2,3,1] Output: [5,6] Input: nums = [1,1] Output: [2] Tip) The intuition behind using a hash map is pretty clear in this case 🖥 실행 1) Answer(Hash Table) class Solution(object): def findDisappearedNumbers(self, num..

  • [LeetCode] Third Maximum Number

    [LeetCode] Third Maximum Number

    🔍 문제 Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number. Input: nums = [3,2,1] Output: 1 Explanation: The first distinct maximum is 3. The second distinct maximum is 2. The third distinct maximum is 1. 🖥 실행 1) Answer class Solution: def thirdMax(self, nums: List[int]) -> int: for i in nums: while num..

  • [LeetCode] Max Consecutive Ones II

    [LeetCode] Max Consecutive Ones II

    🔍 문제 Given a binary array nums, return the maximum number of consecutive 1's in the array if you can flip at most one 0. nput: nums = [1,0,1,1,0] Output: 4 Explanation: Flip the first zero will get the maximum number of consecutive 1s. After flipping, the maximum number of consecutive 1s is 4. 🖥 실행 1) Answer class Solution(object): def findMaxConsecutiveOnes(self, nums): # previous and current l..

  • [LeetCode] Height Checker

    [LeetCode] Height Checker

    🔍 문제 A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line. You are given an integer array heights representing the current order that the students are standing in. Eac..

  • [LeetCode] Move Zeroes

    [LeetCode] Move Zeroes

    🔍 문제 Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] Input: nums = [0] Output: [0] 🖥 실행 1) Answer class Solution: def moveZeroes(self, nums: List[int]) -> None: n = 0 while nums.count(0) > n: nums.remove(..