일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- data science
- Generator
- t1
- 43. Multiply Strings
- DWG
- LeetCode
- Substring with Concatenation of All Words
- Python Implementation
- Convert Sorted List to Binary Search Tree
- attribute
- 프로그래머스
- 운영체제
- 715. Range Module
- kaggle
- Class
- concurrency
- Python Code
- shiba
- Python
- 밴픽
- 315. Count of Smaller Numbers After Self
- 30. Substring with Concatenation of All Words
- 파이썬
- Regular Expression
- 109. Convert Sorted List to Binary Search Tree
- 시바견
- Decorator
- iterator
- 컴퓨터의 구조
- Protocol
- Today
- Total
목록Computer Science (392)
Scribbling
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