글로벌
서비스로 운영되는 서비스들의 일부 Event 들이 Default 로 미국 동부 (버지니아 북부) us-east-1
로 전송됩니다.다른 계정 또는 리전의 이벤트 버스
를 지정할 수 있습니다.기존 Spring MVC는 하나의 요청에 대해 하나의 스레드
가 사용된다
리액티브 프로그래밍 방식을 사용
하여 논블로킹과 고정된 스레드로 모든 요청을 처리
하여 기존의 문제를 해결한다.
반응형 프로그래밍(Reactive Programming)
방식을 통해 Event-Driven(이벤트 기반)의 비동기식 애플리케이션
을 구축reference
큐
를 두고 서비스를 개발하게 되었다.큐
서비스는 다중화 구성을 기본으로 장애 걱정 없이 믿을 만한 시스템으로 구축리소스 유형 | Amazon SNS | Amazon SQS | Amazon MQ |
---|---|---|---|
동기식 | 아니요 | 아니요 | 예 |
비동기식 | 예 | 예 | 예 |
대기열 | 아니요 | 예 | 예 |
게시자-구독자 메시징 | 예 | 아니요 | 예 |
메시지 브로커 | 아니요 | 아니요 | 예 |
특징 | SNS | SQS |
---|---|---|
이름 | Simple Notification Service | Simple Queue Service |
메시지를 발행하는 곳 | Topic(Pub/Sub) | Queue |
메시지 소비자 특징 | 게시자 (생산자라고도 함) 에서 여러 구독자 엔드포인트 (소비자라고도 함) 로 메시지를 전송하는 게시-구독 서비스 | 대기열에 있는 메시지는 일반적으로 단일 구독자가 처리 |
전송 방식 | Push: 사용자에게 메세지 전송 | Pull: 사용자가 메세지를 가져온다 |
Fanout: 같은 메세지를 여러 방향으로 발행 | Decouple: 여러 서비스로 분리하여 병렬식 비동기 처리 | |
메세지를 받는 사용자가 없으면 몇 번 시도하다가 삭제된다. 전송 후 보관 없이 메시지가 사라지는 방식 | 메세지는 일정 기간동안 유지된다. (최대 14일) | |
Publisher(게시자)가 Subscriber(구독자)에게 메세지를 전송하는 관리형 서비스 | 마이크로서비스, 분산 시스템 및 서버리스 애플리케이션을 쉽게 분리하고 확장할 수 있도록 지원하는 완전관리형 메세지 대기열 서비스 | |
Publisher는 Topic(주제)에 메세지를 발행한다.Topic은 수많은 Subscribers(구독자들)에게 전달될 수 있다.(fan out)이때 전달 방식은 다양하다.(Lambda, SQS, Email …) | 시스템은 Queue로부터 새로운 이벤트를 실시할 수 있다.Queue에 있는 메세지들은 한 명의 consumer(고객) 또는 하나의 서비스에서 실행된다. | |
다른 시스템들이 이벤트에 신경쓰는가? Topic에 메세지를 publish(발행)하고 싶어하고, 사람들에게 발행되었다고 알리고 싶을 때 | 이 시스템이 이벤트에 신경쓰는가? 내가 이벤트의 수신자일 때 |
reference
Given the roots of two binary trees p and q, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.
Example 1:
Input: p = [1,2,3], q = [1,2,3]
Output: true
Example 2:
Input: p = [1,2], q = [1,null,2]
Output: false
Example 3:
Input: p = [1,2,1], q = [1,1,2]
Output: false
Constraints:
I solved this problem like this.
class Solution:
def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
def dfs(node, ans):
if not node:
ans.append(node)
return
ans.append(node.val)
dfs(node.left, ans) if node.left else ans.append(node.left)
dfs(node.right, ans) if node.right else ans.append(node.right)
ans1, ans2 = [], []
dfs(p, ans1), dfs(q, ans2)
return ans1 == ans2
Given an integer x, return true if x is a palindrome, and false otherwise.
Example 1:
Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.
Example 2:
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Constraints:
I solved this problem like this.
class Solution:
def isPalindrome(self, x: int) -> bool:
return str(x) == str(x)[::-1]
Reverse bits of a given 32 bits unsigned integer.
Note:
Example 1:
Input: n = 00000010100101000001111010011100
Output: 964176192 (00111001011110000010100101000000)
Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.
Example 2:
Input: n = 11111111111111111111111111111101
Output: 3221225471 (10111111111111111111111111111111)
Explanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111.
Constraints:
I solved this problem like this.
class Solution:
def reverseBits(self, n: int) -> int:
bi_num = '{0:032b}'.format(n)
ans = int(bi_num[::-1], 2)
return ans
Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.
You must implement a solution with a linear runtime complexity and use only constant extra space.
Example 1:
Input: nums = [2,2,3,2]
Output: 3
Example 2:
Input: nums = [0,1,0,1,0,1,99]
Output: 99
Constraints:
I solved this problem like this.
class Solution:
def singleNumber(self, nums: List[int]) -> int:
dic = {}
for x in nums:
if x not in dic:
dic[x] = 0
dic[x] += 1
for key in dic:
if dic[key] == 1:
return key
return -1
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.
Example 1:
Input: numCourses = 2, prerequisites = [[1,0]]
Output: true
Explanation: There are a total of 2 courses to take.
To take course 1 you should have finished course 0. So it is possible.
Example 2:
Input: numCourses = 2, prerequisites = [[1,0],[0,1]]
Output: false
Explanation: There are a total of 2 courses to take.
To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible.
Constraints:
I solved this problem like this.
class Solution:
def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
adj = {}
indegree = [0] * numCourses
is_visited = [0] * numCourses
for second, first in prerequisites:
indegree[second] += 1
if first not in adj:
adj[first] = []
adj[first].append(second)
node_list = [i for i, x in enumerate(indegree) if x == 0]
node_list = deque(node_list)
while node_list:
node = node_list.popleft()
if is_visited[node]:
continue
is_visited[node] = 1
if node not in adj:
continue
for next_node in adj[node]:
indegree[next_node] -= 1
if indegree[next_node] == 0:
node_list.append(next_node)
return sum(is_visited) == numCourses
Given an array of strings strs, group the anagrams together. You can return the answer in any order.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Example 1:
Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Example 2:
Input: strs = [""]
Output: [[""]]
Example 3:
Input: strs = ["a"]
Output: [["a"]]
Constraints:
I solved this problem like this.
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
dic = {}
for s in strs:
key = ''.join(sorted(s))
if key not in dic:
dic[key] = []
dic[key].append(s)
ans = []
for key in dic:
ans.append(dic[key])
return ans
209. Minimum Size Subarray Sum
Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, return 0 instead.
Example 1:
Input: target = 7, nums = [2,3,1,2,4,3]
Output: 2
Explanation: The subarray [4,3] has the minimal length under the problem constraint.
Example 2:
Input: target = 4, nums = [1,4,4]
Output: 1
Example 3:
Input: target = 11, nums = [1,1,1,1,1,1,1,1]
Output: 0
Constraints:
I solved this problem like this.
class Solution:
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
for l in range(1, len(nums)+1):
value = sum(nums[:l])
# check value
if value >= target:
return l
for i in range(0, len(nums)-l):
# value change
value = value - nums[i] + nums[i+l]
# check value
if value >= target:
return l
return 0
sum between right and left >= target
, move left cursor[2,3,1,2,4,3] total = 2, left = 0, right = 0, ans = 987654321
^
[2,3,1,2,4,3] total = 5, left = 0, right = 1, ans = 987654321
^ ^
[2,3,1,2,4,3] total = 6, left = 0, right = 2, ans = 987654321
^ ^
[2,3,1,2,4,3] total = 8, left = 0, right = 3, ans = 4
^ ^
[2,3,1,2,4,3] total = 6, left = 1, right = 3, ans = 4
^ ^
[2,3,1,2,4,3] total = 10, left = 1, right = 4, ans = 4
^ ^
[2,3,1,2,4,3] total = 7, left = 2, right = 4, ans = 4
^ ^
[2,3,1,2,4,3] total = 6, left = 3, right = 4, ans = 4
^ ^
[2,3,1,2,4,3] total = 9, left = 3, right = 5, ans = 4
^ ^
[2,3,1,2,4,3] total = 7, left = 4, right = 5, ans = 2
^ ^
class Solution:
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
ans = 987654321
left, total = 0, 0
for right in range(len(nums)):
total += nums[right]
while total >= target:
ans = min(ans, right - left + 1)
total -= nums[left]
left += 1
return ans if ans != 987654321 else 0