Zero to Hero
article thumbnail
22. Generate Parentheses
Algorithm 2021. 4. 5. 13:30

Generate Parentheses - 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 1. Brute Force (특정 길이의 괄호 문자열을 전부 만들고 적합한지 판단) from typing import * class Solution: answer = [] def generateParenthesis(self, n: int) -> List[str]: self.answer=[] self.dfs("", n) return self.answer def dfs(self,..

2105. [모의 SW 역량테스트] 디저트 카페
Algorithm 2021. 4. 4. 23:34

SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com from collections import deque def is_possible(x, y, length): if 0

article thumbnail
15. 3Sum
Algorithm 2021. 4. 2. 16:18

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 1. Two Pointer를 사용한 풀이(내 풀이, start, index, end) from typing import * class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: answer = [] nums.sort() # -4 -1 -1 0 1 2 for i in range(1, len(nums) - 1): start, end ..

article thumbnail
5. Longest Palindromic Substring
Algorithm 2021. 4. 1. 23:39

Longest Palindromic Substring - 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 1. DP를 이용한 풀이 class Solution(object): def longestPalindrome(self, s): dp=[[0]*len(s) for _ in range(len(s))] answer=s[0] for i in range(len(s)): dp[i][i]=1 for i in range(len(s)-1): if s[i]==s[i+1]: dp[..

Python 코딩테스트 팁 01 - 전역 변수
Algorithm 2021. 3. 30. 16:37

Python에는 지역 변수, 전역 변수 개념이 있다. 기본적으로 script 언어 형태를 띠기 때문에 구분하는 게 약간 애매하지만 아래와 같다. global_variable = 100 print(global_variable) # 100 def func(): local_variable = 200 print(local_variable) # 200 print(global_variable) # 100 func() 한 가지 특이한 점이 있다면 func() 안에서 global_variable을 찾을 수 있다는 점이다. 기본적으로 Python은 호출된 스코프에서 해당 변수를 찾고, 만약에 스코프에 그 변수가 없다면 그다음 스코프에서 변수를 찾는다. 위 경우 func() 안에서 global_variable을 찾았는데 ..

정수 내림차순으로 배치하기
Algorithm 2021. 3. 22. 15:48

programmers.co.kr/learn/courses/30/lessons/12933 코딩테스트 연습 - 정수 내림차순으로 배치하기 함수 solution은 정수 n을 매개변수로 입력받습니다. n의 각 자릿수를 큰것부터 작은 순으로 정렬한 새로운 정수를 리턴해주세요. 예를들어 n이 118372면 873211을 리턴하면 됩니다. 제한 조건 n은 1이 programmers.co.kr 내가 짠 Java 코드 import java.util.Arrays; class Solution { public long solution(long n) { String nString=Long.toString(n); String[] arr=nString.split(""); Arrays.sort(arr); StringBuilder b..