일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Python
- Generator
- Substring with Concatenation of All Words
- Regular Expression
- Python Code
- 715. Range Module
- 운영체제
- 파이썬
- iterator
- Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- 프로그래머스
- kaggle
- 밴픽
- shiba
- concurrency
- data science
- t1
- LeetCode
- 109. Convert Sorted List to Binary Search Tree
- Python Implementation
- Protocol
- 43. Multiply Strings
- Decorator
- 컴퓨터의 구조
- Class
- 30. Substring with Concatenation of All Words
- attribute
- DWG
- 시바견
- Today
- Total
목록전체 글 (382)
Scribbling
Q: Find the number of unique strings of which the length is L, given that the maximum number of consecutive vowels allowed is K. * There are 21 types of consonants and 5 types of vowels. For example, L=4, K=1: then allowed patterns are - CCCC CCCV, CCVC, CVCC, VCCC, VCVC, VCCV, CVCV This question can be easily handled with DFS. However, the approach would not be optimal as it involves unnecessar..
A dynamic programming approach: Let dp[i, j] be the total number of cases of target[i] corresponding to jth position dp[i, j] = dp[i][j-1] + dp[i-1][j-1] * counter[j, target[i]] 1) Bottom-up import string from functools import lru_cache class Solution: def numWays(self, words: List[str], target: str) -> int: N = len(words[0]) freqs = [{c: 0 for c in string.ascii_lowercase} for _ in range(N)] for..
class Solution { public int eraseOverlapIntervals(int[][] intervals) { if (intervals.length == 0) return 0; Arrays.sort(intervals, new Comparator(){ @Override public int compare(int[] o1, int[] o2) { return o1[1]-o2[1]; } }); int cnt = 1; int end = intervals[0][1]; for (int i=1; i= end) { cnt += 1; end = intervals[i][1]; } } return intervals.length - cnt; } }
class TrieNode { public boolean isWord = false; public TrieNode[] children = new TrieNode[26]; } class Trie { public TrieNode root; public Trie() { root = new TrieNode(); } public void insert(String word) { TrieNode cur = root; for (int i=0; i
Greedy solution with heap & deque - append character with 'max frequency' currently - put the appended character to a deque for cool-down from collections import Counter, deque import heapq class Solution: def rearrangeString(self, s: str, k: int) -> str: if k = k: freq, char = q.popleft() if freq >= 1: heapq.heappush(h, (-freq, char)) return ''.join(ret) if len(ret) == len(s) else ""
LeetCode: 208. Implement Trie (Prefix Tree) class TrieNode { public boolean isWord = false; public TrieNode[] children = new TrieNode[26]; } class Trie { public TrieNode root; public Trie() { root = new TrieNode(); } public void insert(String word) { TrieNode cur = root; for (int i=0; i
Java STL provides ArrayDeque, LinkedList, and PriorityQueue. - LinkedList maintains the input order. - ArrayDeque maintains the input order as well. However, ArrayDeque is more efficient in terms of memory than LinkedList. LinkedList, on the other hand, is efficient when we need to remove elements frequently. - PriorityQueue maintains the natural order of data. For BFS, consider using ArrayDeque..
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */ class Solution { public ListNode mergeKLists(ListNode[] lists) { if (lists == null || lists.length == 0) { return null; } PriorityQueue pq = new PriorityQueue( lists.l..
Fenwick Tree (or Binary Indexed Tree) is very efficient in dealing with range queries, especially when elements get updated occasionally. For how it works, refer to the below video. He elaborates on the principle of the tree in a very clean way. https://www.youtube.com/watch?v=CWDQJGaN1gY&t=160s&ab_channel=TusharRoy-CodingMadeSimple Below is the python implementation of it. class Fenwick: """ Py..
class Solution { public boolean isValid(String s) { Stack stack = new Stack(); for (var c: s.toCharArray()) { if (c == '{' || c == '[' || c == '(') { stack.add(c); } else { if (stack.empty()) return false; Character popped = stack.pop(); if (c == '}') { if (popped != '{') return false; } else if (c == ']') { if (popped != '[') return false; } else if (c == ')') { if (popped != '(') return false;..