일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Decorator
- Substring with Concatenation of All Words
- DWG
- Python
- Generator
- data science
- Regular Expression
- Protocol
- 30. Substring with Concatenation of All Words
- 715. Range Module
- 43. Multiply Strings
- shiba
- t1
- 시바견
- 프로그래머스
- 315. Count of Smaller Numbers After Self
- 파이썬
- Class
- concurrency
- 109. Convert Sorted List to Binary Search Tree
- Convert Sorted List to Binary Search Tree
- 운영체제
- attribute
- iterator
- 밴픽
- kaggle
- LeetCode
- Python Code
- 컴퓨터의 구조
- Python Implementation
- Today
- Total
목록분류 전체보기 (407)
Scribbling
Immutable dictionary: MappingProxyType Immutable Set: Frozenset from types import MappingProxyType d = {'a': 'apple', 'b': 'banana', 'c': 'carrot'} d_fixed = MappingProxyType(d) print(d_fixed['a']) s = frozenset([1, 2, 3]) print(s)
1. List / Generator Comprehension Using list / generator comprehension makes code more readable while enhancing efficiency. suits = ['Spades', 'Diamonds', 'Hearts', 'Clubs'] ranks = [str(i) for i in range(2, 11)] + list('JQKA') for card in (f"{suit} {rank}" for suit in suits for rank in ranks): print(card) 2. Tuple Unpacking a, b, *rest = range(1, 5) print(a, b, rest) 3. NamedTuple Namedtuple is..
We need to deal with ranges to solve this problem. Below is the link of a wonderful solution. https://leetcode.com/problems/range-module/discuss/244194/Python-solution-using-bisect_left-bisect_right-with-explanation Python solution using bisect_left, bisect_right with explanation - LeetCode Discuss Level up your coding skills and quickly land a job. This is the best place to expand your knowledg..
Staying healthy is perhaps one of the most important things in our lives. However, it is also one of the hardest tasks. As life expectancy increases, staying healthy is becoming more and more essential. Personally, I haven’t tried much to be in good health until recently. However, as I got older, it became very obvious that I must make some effort to stay healthy. As many knows, human body recov..
Personally, I suffered from a skin rash every time I got the vaccine. It was a very hard time for me as it kept appearing more than a month. What’s even worse about it is that I got infected with the virus even after I got the third vaccine. I am very aware that getting vaccinated doesn’t guarantee that one will never get infected with the virus, but still I feel very unfair because of all the s..
In this post, I am dealing with 'magic methods' to create more pythonic data models. First Example: Card Deck Card = namedtuple('Card', ['rank', 'suit']) class FrenchDeck: ranks = [str(n) for n in range(2, 11)] + list('JQKA') suits = ['Spades', 'Diamonds', 'Hearts', 'Clubs'] def __init__(self): self._cards = [Card(rank, suit) for suit in FrenchDeck.suits for rank in FrenchDeck.ranks] def __len__..
The very first thing to do is looking for matches. We don't need to use any fancy algorithms when looking for matches in this problem because it is guranteed that replacements will not overlap. Now we have matched list in the form of [index, source, target]. If you are planning to replace s directly, it will lead to bad time complexity as you will have to copy all the characters of s each time y..
1. Use deep copy list function copy() can be troublesome when the list has mutable objects. from copy import deepcopy l1 = [1, 2, [3, 4]] l2 = l1.copy() l3 = deepcopy(l1) l1[1] = 3 l1[2][0] = 4 print(l2) print(l3) 2. while--else for--else else part is executed when the loop is stopped by 'break' or when the loop wasn't executed. i = 0 while i > 10: print(i) else: print('no') for x in range(10): ..
class Solution: def calculate(self, s: str) -> int: # ' ' is intentionally added, # to mark the end of the given string s # encountering ' ' will add the last number to the stack self.s = s + ' ' self.ptr = 0 return self.calc() def calc(self): num, stack, sign = 0, [], '+' while self.ptr < len(self.s): c = self.s[self.ptr] # if met with '(', # get the evaluated number by recursion if c == '(': s..
Using double trie structures for prefix and suffix. Somewhat straightforward if one already knows about trie. If not, refer to "LeetCode prob 208. Implement Trie (Prefix Tree)". class WordFilter: def __init__(self, words: List[str]): wordDict = {} for idx, word in enumerate(words): wordDict[word] = idx self.PrefixTree = {} self.SuffixTree = {} for word, idx in wordDict.items(): node = self.Prefi..