Slide 1

Slide 1 text

競技プログラミングプログラミングサイトでで Pythonを学ぶ学ぶぶ By ksnt

Slide 2

Slide 2 text

代表的な競技プログラな競技プログラミ競技プログラミングプログラミングサイトで (私見) ● AtCoder ● Topcoder ● Codeforces ● LeetCode (面接対策?) └ 過去問 └ mock (模擬試験?) └ コンテストで ● HackerRank (面接対策?) ● ProjectEuler (数学ぶ) ● Kaggle (データサイエンス) ※黄色くマーカーを引くマーカーを引いマーカーを学ぶ引いたものはやっいたものはやったことがある ※日本人ははAtCoderを学ぶやっている人はを学ぶよくマーカーを引い見かける 参考) コーディング面接対策のために解きたい解きたいきたいLeetCode 60問 https://1kohei1.com/leetcode/

Slide 3

Slide 3 text

競技プログラミングプログラミングとは 参加者全員に同一の課題がに解きたい同一の課題が出題さの課題が出題され、よが出題が出題され、よされ、より早く早くくマーカーを引い 与えられた要求をえられた要求を満足するプロを学ぶ満足するプログラムするプログラムを正確にを学ぶ正確にに解きたい 記述することを競うすることを学ぶ競う。(Wikipedia)

Slide 4

Slide 4 text

な競技プログラミぜ競技プログラミ競技プログラミングプログラミング を学ぶやるのか?(私見) 1. 名誉のためのため(レッドコーダー,グランドマスターetc) 2. コーディング面接対策 3. プログラミング学ぶ習 4. 楽しいからしいから(楽しいからしくマーカーを引いプログラミング、ゲームを正確に感覚)

Slide 5

Slide 5 text

どのプラットでフォームを正確にでやり早くはじめ ればいいの? ● 数学ぶが趣味の人 の人は => ProjectEuler ● データサイエンスが好き き => Kaggle ● 面接対策 企業面接の過去問が解きたいきたい => LeetCode 過去問でな競技プログラミくマーカーを引いてもよい => HackerRank ● 楽しいからしそう => どれでもOK!

Slide 6

Slide 6 text

LeetCodeの見た目(1)

Slide 7

Slide 7 text

LeetCodeの見た目(2)

Slide 8

Slide 8 text

HackerRankの見た目

Slide 9

Slide 9 text

第1問

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

解きたい答 if __name__ == '__main__': n = int(input()) print(*range(1,n+1),sep='')

Slide 12

Slide 12 text

第2問

Slide 13

Slide 13 text

問題が出題され、よ Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right. Note that elements beyond the length of the original array are not written. Do the above modifications to the input array in place, do not return anything from your function. class Solution: def duplicateZeros(self, arr: List[int]) -> None: """ Do not return anything, modify arr in-place instead. """

Slide 14

Slide 14 text

解きたい答

Slide 15

Slide 15 text

休憩

Slide 16

Slide 16 text

最終問題が出題され、よ

Slide 17

Slide 17 text

LRUキャッシュの実装の実装 Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1. put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item. The cache is initialized with a positive capacity. Follow up: Could you do both operations in O(1) time complexity? class LRUCache: def __init__(self, capacity: int) def get(self, key: int) -> int:: def put(self, key: int, value: int) -> None: Example: LRUCache cache = new LRUCache( 2 /* capacity */ ); cache.put(1, 1); cache.put(2, 2); cache.get(1); // returns 1 cache.put(3, 3); // evicts key 2 cache.get(2); // returns -1 (not found) cache.put(4, 4); // evicts key 1 cache.get(1); // returns -1 (not found) cache.get(3); // returns 3 cache.get(4); // returns 4

Slide 18

Slide 18 text

解きたい答 import collections class LRUCache: def __init__(self, capacity: int): self.capacity = capacity self.cache = collections.OrderedDict() def get(self, key: int) -> int: if key in self.cache.keys(): tmp = self.cache[key] self.cache.pop(key) self.cache[key] = tmp return tmp else: return -1 def put(self, key: int, value: int) -> None: if key not in self.cache.keys(): if len(self.cache) >= self.capacity: self.cache.popitem(last=False) # last=False -> FIFO else: self.cache.pop(key) self.cache[key] = value # Your LRUCache object will be instantiated and called as such: # obj = LRUCache(capacity) # param_1 = obj.get(key) # obj.put(key,value)

Slide 19

Slide 19 text

まとめ ● 競技プログラミングプログラミングサイトではコンテストでに解きたい参加 しな競技プログラミくマーカーを引いても楽しいからしめるし勉強できる(私はわできる(私はわりと私はわり早くと こういう使い方をしているい方をしている)を学ぶしている) ● 自分にあったプラッに解きたいあったプラットでフォームを正確にを学ぶ見つけて楽しいからし くマーカーを引い学ぶびましょう!