분류 전체보기

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Example 1:Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] n 이라는 limit이 있으면,여는 괄호 수를 openN, 닫는 괄호 수를 closeN이라고 했을 때closeN closeN > openN이 되면 well-formed parentheses가 되지 못하기 때문이다. 아래와 같이 트리 구조를 그려보며 가능한 경우의 수를 생각해볼 수 있다.  풀이1: 백트래킹, stack 이용class Solution: def generateParen..
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.Notice that the solution set must not contain duplicate triplets. 풀이 1: 브루트 포스 - 시간 초과class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: res = set() nums.sort() for i in range(len(nums)): ..
Postfix NotationYou are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.Evaluate the expression. Return an integer that represents the value of the expression.Note that:The valid operators are '+', '-', '*', and '/'.Each operand may be an integer or another expression.The division between two integers always truncates toward zero.There will ..
Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2.The tests are generated such that there is exactl..
URL을 브라우저에 입력했을 때 일어나는 과정을 딥하게 알아보자! 1. URL 파싱브라우저는 입력된 URL을 해석하여 프로토콜 / 도메인 네임 / 경로 / 쿼리 매개변수 등으로 분리한다.브라우저는 URL에서 example.com 이라는 도메인 네임을 추출하고 이를 통해 DNS 쿼리가 시작된다.  2. DNS (Domain Name System) 조회Domain Name은 사람이 이해하기 쉬운 주소지만, 컴퓨터는 IP 주소를 통해 통신한다.DNS는 도메인 네임을 IP로 변환하기 위해 존재한다. 웹 브라우저는 DNS 서버에 검색하기 전에 캐싱된 DNS 기록을 먼저 확인한다.캐시에 해당 정보가 없다면, 브라우저는 도메인을 IP 주소로 변환하기 위해 DNS 서버에 요청을 보낸다. 이 요청은 사용자의 ISP(In..
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.Implement the MinStack class:- MinStack() initializes the stack object.- void push(int val) pushes the element val onto the stack.- void pop() removes the element on the top of the stack.- int top() gets the top element of the stack.- int getMin() retrieves the minimum element in the stack.You must i..
Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.Each column must contain the digits 1-9 without repetition.Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.Note:A Sudoku board (partially filled) could be valid but is not necess..
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.You must write an algorithm that runs in O(n) time.longest consecutive sequence를 찾는 문제! O(n) 안으로 풀어야 한다.주의할 점은 constraints에 nums의 length가 0부터 가능하다는 것  Hash Set을 이용한 풀이class Solution: def longestConsecutive(self, nums: List[int]) -> int: numSet = set(nums) longest = 0 f..
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.Given a string s, return true if it is a palindrome, or false otherwise.유효한 palindrome(회문) 검사하는 메서드 구현하기! 풀이1: Reverse Stringclass Solution: def isPalindrome(self, s:..
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brackets.Open brackets must be closed in the correct order.Every close bracket has a corresponding open bracket of the same type.괄호가 올바르게 짝지어졌는지 확인하는 문제! 풀이1: Stack 이용class Solution: def isValid(sel..
yesolz
'분류 전체보기' 카테고리의 글 목록 (3 Page)