본문 바로가기

분류 전체보기

(248)
Django + nginx + uwsgi 배포 - new-bpp.pem 있는 위치에서 WSL2 통해 인스턴스 접속 sudo ssh -i "new-bpp.pem" ubuntu@15.164.119.31 - 서버에 변동사항이 있다면 python manage.py collectstatic python manage.py migrate sudo service nginx restart sudo service uwsgi restart - 서버 주소 http://15.164.119.31/
8/3 스터디 정리중 reverse(): 리스트반환 reversed(): reversed객체반환(형변환필요) ''.join(reversed(str)) 문자열뒤집기 문자열 뒤집기 str[::-1] max함수: key를 기준으로 최대반환 예외 부분들 잘 처리하기 dp[i][j] 인덱스 i부터 j까지 팰린드롬인지 True .index에서 해당값없으면 에러난다 find는 이터레이터 반환, find_if도 있다 .end()는 마지막에서 하나 더 뒤 .begin()는 맨첫번째 set에 리스트 여러개가 안먹는다 벡터에 erase로 지울수 있다 vector는 erase하나만 ::iterator 붙이는건 저거에 대한 이터레이터 쓴다는뜻 array 자료형 list 자료형 vector 자료형 capacity와 size차이 erase와 remov..
[배열] 12 주식을 사고팔기 가장 좋은 시점(Best Time to Buy and Sell Stock) https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ Best Time to Buy and Sell Stock - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 한 번의 거래로 낼 수 있는 최대 이익을 산출하는 문제입니다. 이 문제는 N이 최대 105이므로 브루트포스를 통한 O(N2)으로는 풀 수 없습니다. 처음 풀이한 코드는 다음과 같습니다. 가격의 최저점을 갱신해나가고, 최저점보다 가격이 높다면 시세..
[배열] 11 자신을 제외한 배열의 곱(Product of Array Except Self) https://leetcode.com/problems/product-of-array-except-self/ Product of Array Except Self - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 배열을 입력받아 output[i]가 자신을 제외한 나머지 모든 요소의 곱셈 결과가 되도록 출력하는 문제입니다. 이때 나눗셈을 하지 않고 O(N)에 풀이해야 되는 점이 핵심입니다. 처음에 머리에 든 생각은 미리 전체 곱셈 값을 구해놓고 각 항목별로 자기 자신..
[배열] 10 배열 파티션 I(Array Partition I) https://leetcode.com/problems/array-partition-i/ Array Partition I - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com n개의 페이를 이용한 min(a,b)의 합으로 만들 수 있는 가장 큰 수를 출력하는 문제입니다. 두 페어씩 묶어서 최대한 크게 만들어야 하는데, 예시를 살펴보면 모두 정렬후에 앞에서부터 2개씩 묶습니다. 따라서 짝수index(0,2,4,...)인 값들의 합이 문제의 답입니다.(정렬된 상태에서 짝..
[배열] 09 세 수의 합(3Sum) https://leetcode.com/problems/3sum/ 3Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 배열을 입력받아 합으로 0을 만들 수 있는 3개의 엘리먼트를 출력하는 문제입니다. 배열 길이의 최댓값이 3000이므로 브루트포스를 통한 O(N3)으로는 시간초과가 납니다. 따라서 배열을 정렬한 이후에 투 포인터를 이용해서 간격을 좁혀나가며 sum을 계산해 나가야 합니다. sum이 0보다 작다면 left를 우측으로, 0보다 크다면 right를..
[배열] 08 빗물 트래핑(Trapping Rain Water) ✔ https://leetcode.com/problems/trapping-rain-water/ Trapping Rain Water - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 높이를 입력받아 비 온 후 얼마나 많은 물이 쌓일 수 있는지 계산하는 문제입니다. 이 문제는 높이와 너비 모든 공간을 차례대로 모두 살펴보면 O(N2)에 풀이가 가능합니다. 그러나 시간복잡도가 너무 높기 때문에 투 포인터나 스택으로 O(N)에 풀이할 수 있습니다. 투 포인터를 통해 풀이한..
[배열] 07 두 수의 합(Two Sum) ✔ https://leetcode.com/problems/two-sum/ Two Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 덧셈하여 타겟을 만들 수 있는 배열의 두 숫자 인덱스를 리턴해야 합니다. 단순히 브루트 포스로 모든 경우를 살펴보면 다음과 같습니다. class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): for j ..