분류 전체보기

    [LeetCode] Replace Elements with Greatest Element on Right Side

    [LeetCode] Replace Elements with Greatest Element on Right Side

    🔍 문제 Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1. After doing so, return the array. Input: arr = [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Explanation: - index 0 --> the greatest element to the right of index 0 is index 1 (18). - index 1 --> the greatest element to the right of index 1 is in..

    [LeetCode] Valid Mountain Array

    [LeetCode] Valid Mountain Array

    🔍 문제 Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if: arr.length >= 3 There exists some i with 0 ... > arr[arr.length - 1] Input: arr = [2,1] Output: false Input: arr = [3,5,5] Output: false Input: arr = [0,3,2,1] Output: true 🖥 실행 ..

    [LeetCode] Merge Sorted Array

    [LeetCode] Merge Sorted Array

    🔍 문제 You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a ..

    [LeetCode] Find Numbers with Even Number of Digits

    [LeetCode] Find Numbers with Even Number of Digits

    🔍 문제 Given an array nums of integers, return how many of them contain an even number of digits. nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits (even number of digits). 345 contains 3 digits (odd number of digits). 2 contains 1 digit (odd number of digits). 6 contains 1 digit (odd number of digits). 7896 contains 4 digits (even number of digits). Therefore only 12 and 7896 c..

    [while 반복문] 소인수 분해

    [while 반복문] 소인수 분해

    🔍 문제 - 입력 받은 수를 반복문을 통해 소인수 분해 🖥 실행 inputNum = int(input("수 입력: ")) n = 2 searchNum = [] while n

    [for 반복문] 최소 공배수 구하기

    [for 반복문] 최소 공배수 구하기

    🔍 문제 -어느 음식점의 식료품 배달 주기가 각각 다를 때, 3 가지 물품이 동시에 들어오는 날짜를 계산 과일 = 3일 주기, 생선 = 4일 주기, 야채 = 5일 주기 🖥 실행 fruit = 3 fish = 4 vege = 5 maxNum = 0 for i in range(1, fruit+1): if fruit % i ==0 and fish % i == 0: print('공약수는 {}'.format(i)) maxNum = i print('최대공약수는 {}'.format(maxNum)) minNum = (fruit*fish)//maxNum newNum = minNum for i in range(1, newNum+1): if newNum % i == 0 and vege % i ==0: maxNum = i ..

    [while 반복문] 공약수, 최대 공약수 구하기

    [while 반복문] 공약수, 최대 공약수 구하기

    🔍 문제 반복문을 이용하여 공약수, 최대 공약수 구하기 🖥 실행 num1 = int(input('0보다 큰 수 입력:')) num2 = int(input('0보다 큰 수 입력:')) temp1 = num1 temp2 = num2 while temp2 > 0: temp = temp2 temp2 = temp1 % temp2 temp1 = temp print('{}와 {}의 최대공약수 : {}'.format(num1,num2,temp1)) for i in range(1, temp1+1): if temp1 % i == 0: print('{}와 {}의 공약수: {}'.format(num1,num2,i)) 📝 결과물 0보다 큰 수 입력:27 0보다 큰 수 입력:90 27와 90의 최대공약수 : 9 27와 90의 공..

    [기초수학] 순열과 조합

    [기초수학] 순열과 조합

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