전체 글 79

[Leetcode] 771. Jewels and Stones

Problem 이번 문제는 jewels 와 존 스톤스를 준다 존 스톤스 안에 jewels 가 몇개인지를 결과로 내줘야 하는 문제이다 나의 풀이 class Solution: def numJewelsInStones(self, jewels: str, stones: str) -> int: res = 0 for i in jewels: res += stones.count(i) return res jewels 를 하나씩 돌려주면서 존스톤스 안에 몇개있는지 count를 사용하여 문제를 해결했다 다른 사람의 존스톤스 풀이를 보자 class Solution: def numJewelsInStones (self, J: str, S: str) -> int: jset = set(J) count = 0 for i in S: if ..

Python/algorithm 2022.12.27

[Leetcode] 1672. Richest Customer WealthEasy2.9K305

Problem 이번 문제는 리스트 안에 리스트 의 합 중에서 최대 값을 return 하는 쉬운 문제이다 나의 풀이 class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: res = [sum(account) for account in accounts] return max(res) 기본적인 sum 과 max를 이용하여 문제를 풀었다 당연히 다른사람의 머리속을 들어가 봐야한다. class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(map(sum, accounts)) 오..... 굉장하다 map을 사용하여 정말 간결하게 코드를 구현했다..

Python/algorithm 2022.12.26

[Leetcode] 1512. Number of Good Pairs

Problem 이번 문제는 배열 안에 같은 값을가지는 ( i,j ) 쌍이 몇가지 있는지 찾는 문제이다 나의 풀이 class Solution: def numIdenticalPairs(self, nums: List[int]) -> int: res = 0 import itertools a_list = itertools.combinations(nums,2) for i in a_list: if i[0] == i[1]: res += 1 return res 이전에 itertools에 있는 combinations를 사용한 기억을 되살려 저걸 활용해서 문제를 풀었다 itertools.combinations(iterable , r) combinations는 iterable 한 객체를 r 의 길이를 가진 조합들을 뽑아내준다..

Python/algorithm 2022.12.25

[Leetcode] 1470. Shuffle the Array

Problem 이번 문제는 굉장히 메마른 영어지식에 문제를 조금 헷갈렸다 ㅋㅋ 쉽게 2n 길이의 array가 주어지고 각 X1, X2 ...Xn ,Y1 , Y2 ... Yn 이렇게 되어 있다고 보면되고 output에서는 X,Y,X,Y ..... X,Y 이런식으로 교차로 섞인 array를 원하고있다! 이전과 다른 약간 짧은 고민 후에 푼 나의 코드 ( 고민을 했다는 것이 중요하다 ) class Solution: def shuffle(self, nums: List[int], n: int) -> List[int]: result = list() for i in range(len(nums)): result.append(nums[i]) result.append(nums[i+n]) if len(a) == len(nu..

Python/algorithm 2022.12.21

[Leetcode] 2011. Final Value of Variable After Performing Operations

Problem - 리스트 안에 ++ 포함 값은 시작값 0 에 1을 더하고 -- 포함 값은 1을 빼서 최종 값을 내는 문제이다 class Solution: def finalValueAfterOperations(self, operations: List[str]) -> int: result = 0 for i in operations: if "--" in i: result -= 1 else: result += 1 return result 그냥 딱 바로 생각나고 대부분 다 이렇게 풀었다고한다. class Solution: def finalValueAfterOperations(self, operations: List[str]) -> int: A=operations.count("++X") B=operations.co..

Python/algorithm 2022.12.20

[Leetcode] 480. Running Sum of 1d Array

Problem - 이 문제는 누적 합을 구하는 문제에용 시원하게 생각나는대로 풀어버린 나의 풀이 class Solution: def runningSum(self, nums: List[int]) -> List[int]: return[sum(nums[:idx+1]) for idx,n in enumerate(nums)] 다른 코드들에 비해 런타임이 길고 메모리사용량이 높아서 너무 궁금해서 다른 풀이 두가지를 찾아보았다 평균적인 런타임 수치의 풀이 class Solution: def runningSum(self, nums: List[int]) -> List[int]: return list(accumulate(nums)) itertools 에 있는 accumulate를 이용하여 값을 뽑았다 ! 누적합을 구해주는 ..

Python/algorithm 2022.12.19

[AWS] AWS CloudWatch를 이용해 경보를 보내 보아용

AWS CloudWatch 에서 service 의 모니터링 지표를 이용하여 특정 정적 임계 값 이상 발생시 알림을 보내거나 자동 인스턴스 재부팅 , 종료 , 중지 등의 작업을 설정 할 수 있다. aws에서 제공하는 경보 설정 Docs https://docs.aws.amazon.com/ko_kr/AmazonCloudWatch/latest/monitoring/ConsoleAlarms.html Example 💡 test-service 에서 발생한 cpu 과다사용으로 인한 서버 다운 현상에 대한 사전 방지 대책 CPU 사용량 35% (주의) 95% (위험) 수신 주제 생성 편집 ( Simple Notificaton Service ) / Amazon SNS 💡 수신 주제 수정 필요 시 ex ) 주제 name = ..

Infra 2022.12.07

[Django] 마이그레이션을 합쳐보아용

Django에서 제공하는 squsashmigrations 을 써봐용 python manage.py squashmigrations python manage.py squashmigrations example 0003 0004 개발자가 직접 Migration을 squash 해용 1. 002(작업 이전 migration)로 migrate를 한다. python manage.py migrate myapp 002 2. 003 이후 migration 파일을 모두 지운다 3. migration을 새로 만든다 python manage.py makemigrations 4. migrate를 한다! 💡 개발자가 직접 하는 것이 기존에 참고할수 있는 이력을 남기고 불필요한 마이그레이션만 지울 수 있어서 관리에 좋아용

Python/Django 2022.12.06