일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Binary
- DP
- hash table
- binary tree
- leetcode
- Array
- matrix
- linked list
- 미디움
- Python
- tree
- 리트코드
- backtracking
- 문자열
- two pointers
- 쉬움
- list
- string
- Depth-first Search
- easy
- 이진트리
- math
- HashTable
- binary search
- recursive
- dfs
- sorting
- Medium
- 재귀
- 중간
- Today
- Total
목록Algorithm/LeetCode (135)
부부의 코딩 성장 일기
1. 문제 링크 https://leetcode.com/problems/zigzag-conversion/ 2. 문제 설명 문자열과 줄 개수가 주어졌을 때, 이를 ↓↗↓↗ 로 반복 배열 한 후, 위에서 아래로 이어붙여서 반환 예시) str= "PAYPALISHIRING", numRows = 3이 주어지면 P A H N A P L S I I G Y I R 로 배열한 후, 위에서 아래로 이어붙여서 "PAHNAPLSIIGYIR"를 반환 3. 처음 풀이 46ms(97.08%), 16.48mb(36.12%) 문제 이름대로 지그재그 움직이는 아이디어 현재 가로 줄이 몇 번째인지 나타내는 변수 position과 위로 갈지 아래로 갈지 방향을 나타내는 변수 direction에 0, 1을 초기 할당함 현재 위치한 가로 줄에..
1. 문제 링크 Number of 1 Bits - LeetCode Number of 1 Bits - LeetCode Can you solve this real interview question? Number of 1 Bits - Write a function that takes the binary representation of an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight [http://en.wikipedia.org/wiki/Hamming_w leetcode.com 2. 문제 설명 10진법 수가 입력되었을 때 이를 32bit로 표현했을 때 1의 개수를 반환하는 문제 예시) 11이..
1. 문제 링크 https://leetcode.com/problems/reverse-bits/ Reverse Bits - LeetCode Can you solve this real interview question? Reverse Bits - Reverse bits of a given 32 bits unsigned integer. Note: * Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed leetcode.com 2. 문제 설명 주어진 정수를 2진법으로 나타낸 후 이를 앞뒤 역순으로 뒤집은 수를 10진법..
1. 문제 링크 LeetCode - The World's Leading Online Programming Learning Platform Excel Sheet Column Number - LeetCode Can you solve this real interview question? Excel Sheet Column Number - Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 leetcode.com 2. 문제 설명 A이 주어..
1. 문제 링크 https://leetcode.com/problems/majority-element/ Majority Element - LeetCode Can you solve this real interview question? Majority Element - Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists leetcode.com 2. 문제 설명 크기가 n인 배열이 주어졌을 때, majority element를 반환..
1. 문제 링크 2. 문제 설명 1이 주어지면 A, 26이 주어지면 Z 27이 주어지면 AA, 28이 주어지면 AB 와 같은 규칙으로 수가 주어졌을 때 문자열을 반환 즉 엑셀의 n번째 열이름을 생각하면 되고 A부터 Z까지 26개이니 26진법으로 생각 26진법이면 26으로 나눈 나머지가 0부터 25까지 나옴 그런데 A~Z까지 0을 나타내는 수가 없다는 것에 유의, 즉 0이 아니라 1이 A가 되고 26이 Z가 되어 1부터 26까지 나와서 하나의 차이가 존재함 3. 처음 풀이 class Solution: def convertToTitle(self, columnNumber: int) -> str: #26으로 나눈 나머지가 0부터 25까지이니 0:'A' 부터 25:'Z'에 대응시켜둔다. #1이 주어지면 1을 뺀 ..
1. 문제 링크 https://leetcode.com/problems/intersection-of-two-linked-lists/ 2. 문제 설명 사이클이 없는 두 개의 연결 리스트(Linked List)가 주어졌을 때 교차하는 곳을 시작점으로 하는 연결 리스트를 반환하는 문제 예시) a1 → a2 → c1 → c2 → c3와 b1 → b2 → b3 → c1 → c2 → c3가 주어지면 c1에서 교차하기 때문에 연결 리스트 c1 → c2 → c3를 반환 3. 처음 풀이 a1을 시작으로 .next를 통해 한 칸 씩 앞으로 가며 끝까지 집합 seen에 저장하고 b1부터 시작하여 seen 에 있는 지 판단하여 아니면 한 칸 전진, 이미 나온 노드면 교차점으로 판단 하여 반환 시간 복잡도 O(m+n) # Def..
1. 문제 링크 https://leetcode.com/problems/binary-tree-preorder-traversal/ Binary Tree Preorder Traversal - LeetCode Can you solve this real interview question? Binary Tree Preorder Traversal - Given the root of a binary tree, return the preorder traversal of its nodes' values. Example 1: [https://assets.leetcode.com/uploads/2020/09/15/inorder_1.jpg] Input: root = [1, leetcode.com 2. 문제 설명 이진 트리의 r..