일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- attribute
- 컴퓨터의 구조
- Python
- t1
- Generator
- 715. Range Module
- Regular Expression
- 밴픽
- concurrency
- Python Code
- 43. Multiply Strings
- Protocol
- data science
- Convert Sorted List to Binary Search Tree
- kaggle
- DWG
- 시바견
- 30. Substring with Concatenation of All Words
- Decorator
- 프로그래머스
- LeetCode
- iterator
- Class
- Substring with Concatenation of All Words
- 운영체제
- 파이썬
- 109. Convert Sorted List to Binary Search Tree
- Python Implementation
- shiba
- 315. Count of Smaller Numbers After Self
- Today
- Total
목록분류 전체보기 (407)
Scribbling
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;..
class Solution { public String minWindow(String s, String t) { String ret = null; Set charSet = t.chars().mapToObj(c -> (char) c) .collect(Collectors.toSet()); List indexList = new ArrayList(); Map need = new HashMap(); for (int i=0; i
class Solution { public boolean isPalindrome(String s) { StringBuilder sb = new StringBuilder(); s.chars().filter(c -> Character.isLetterOrDigit(c)) .mapToObj(c -> Character.toLowerCase((char) c)) .forEach(sb::append); return sb.toString().equals(sb.reverse().toString()); } }
class Solution { public int[] topKFrequent(int[] nums, int k) { Map counter = new HashMap(); for (int num: nums) { counter.put(num, counter.getOrDefault(num, 0) + 1); } Comparator comparator = (list1, list2) -> { for (int i = 0; i < list1.size(); i++) { int value = list1.get(i) - list2.get(i); if (value != 0) return value; } return 0; }; Queue pq = new PriorityQueue(comparator); for (var key: co..
class Solution { public List groupAnagrams(String[] strs) { Map map = new HashMap(); for (String str: strs) { int[] count = new int[26]; Arrays.fill(count, 0); for (char c: str.toCharArray()) { count[c - 'a']++; } StringBuilder sb = new StringBuilder(); for (int i=0; i