| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
- DP
- Depth-first Search
- two pointers
- leetcode
- easy
- sorting
- tree
- list
- 중간
- 리트코드
- HashTable
- Binary
- 쉬움
- binary tree
- linked list
- 문자열
- math
- hash table
- 미디움
- binary search
- recursive
- 재귀
- matrix
- 이진트리
- backtracking
- Array
- string
- Python
- dfs
- Medium
- Today
- Total
목록string (23)
부부의 코딩 성장 일기
1. 문제 링크 https://leetcode.com/problems/add-binary/ 2. 문제 설명 이진법으로 구성된 두개의 문자열 a,b가 주어졌을 때, 두 개의 합을 이진법으로 반환 예시) a= "11", b= "1"이면 십진법으로 3+1= 4이고, 이를 다시 이진법으로 반환한 "100"을 반환 3. 처음 풀이 만약 두 문자열이 0이면 0을 반환, 두 문자열을 더한 값을 십진법으로 반환하고 → 다시 이진법으로 변환하는 식으로 풀이 "11"과 "1"을 더한 "12"를 십진법으로 변환하면, 2*1 + 1*2^1 = 4 4를 계속 2로 나누면서 이진법으로 변환 result = '' (sum_num = 4) result = '0' (sum_num = 2) result = '00' (sum_num = ..
1. 문제 링크 https://leetcode.com/problems/length-of-last-word/ 2. 문제 설명 단어와 공백으로 구성된 문자열 s가 주어졌을 때, 가장 마지막 단어의 길이를 반환 예시) s = "Hello World", output: 5 (마지막 단어인 "World"의 길이 5 반환) 3. 처음 풀이 문자열에 대한 관련 함수를 이미 알고 있어서, 간단하게 해결. s의 양쪽 공백을 없애고, ' ' 기준 split을 한 후, 마지막 element의 lenght를 반환 class Solution: def lengthOfLastWord(self, s: str) -> int: return len(s.strip().split(' ')[-1]) # 양 쪽 공백을 없애고, ' '기준으로 s..
1. 문제 링크 https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/ Find the Index of the First Occurrence in a String - LeetCode Can you solve this real interview question? Find the Index of the First Occurrence in a String - Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Exam..
1. 문제 링크 https://leetcode.com/problems/valid-parentheses/ 2. 문제 설명 (){}[]로만 구성된 string이 주어졌을 때 아래 3가지 요건을 다 만족하는지 판단 - True or False 반환 열린 괄호 ( { ] 는 같은 유형의 괄호에 의해 닫혀야 한다. 열린 괄호는 올바른 순서로 닫혀야 한다. 각 닫는 괄호는 동일 유형의 열린 괄호와 대응해야 한다. 예시) "()" true, "()[]{}" true, "(]" false 3. 처음 풀이 true인 string은 무조건 [], {}, () 중 하나의형태를 포함하고 있다. 단순하게 열고 닫는 괄호 이웃한 것을 한 쌍 한쌍 삭제하는 구조 class Solution: def isValid(self, s: s..
1. 문제 링크 Longest Common Prefix - LeetCode Longest Common Prefix - LeetCode Can you solve this real interview question? Longest Common Prefix - Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Example 1: Input: strs = ["flower","flow" leetcode.com 2. 문제 설명 여러 문자열을 포함한 리스트가 주어졌을 때 모든 문자열의 앞에서부터 최대한 긴 공통 ..
1. 문제 링크 https://leetcode.com/problems/roman-to-integer/ 2. 문제 설명 문제 자체는 심플, 로마 숫자를 정수로 반환하는 함수 (I, V, X ,L, .. 에 대응되는 정수값은 제공이 된다) 다만 숫자로 변환되는 규칙이 약간 생소 → 알고리즘 보다는 규칙을 찾는게 핵심 예시) II : 1+1=2, XII : 10+1+1=12, XXVII : 10+10+2+5=27 헷갈리는 규칙 4는 IIII라 쓰지 않고, IV로 표현 - 5에서 1을 뺀 값으로 작성 I는 4,9를 만들기 위해 V,X 앞에 등장할 수 있고, X는 40,90을 만들기 위해 L,C앞에 등장 가능 3. 처음 풀이 로마 문자를 key, 대응되는 정수를 value로 한 dictionary를 사전에 정의를..
1. 문제 링크 Palindrome Number - LeetCode Palindrome Number - LeetCode Can you solve this real interview question? Palindrome Number - 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. Ex leetcode.com 2. 문제 설명 주어진 int를 뒤에서 앞으로 읽었을 때 같은 정수인 지 판단하는 문제 예시) int=121 이면 ..