전체 글(64)
-
[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 의 길이를 가진 조합들을 뽑아내준다..
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..
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..
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를 이용하여 값을 뽑았다 ! 누적합을 구해주는 ..
2022.12.19 -
[leetcode] 1108. Defanging an IP Address
Problem - 문자열 replace를 이용해 간단하게 풀었땅 class Solution: def defangIPaddr(self, address: str) -> str: return address.replace('.','[.]')
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 = ..
2022.12.07