長野エンジニアライフ

東京から長野に移住したエンジニアのブログです。🦒🗻⛰

データ構造とアルゴリズム

【Pythonで解くLeetCode】 1. Two Sum

問題 与えられたコード 解答コード 学習メモ 問題 leetcode.com Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you m…

二分探索の実装

AIZU ONLINE JUDGEより、二分探索に関する問題(ALDS1_4_B)をpythonで解いていきます。 onlinejudge.u-aizu.ac.jp 問題自体は線形探索の時と同様ですが、入力値のn,qの最大値が増えているため線形探索で解答するとTLEとなります。 ちなみにsetクラスならこち…

線形探索の実装

AIZU ONLINE JUDGEより、線形探索に関する問題(ALDS1_4_A)をpythonで解いていきます。 onlinejudge.u-aizu.ac.jp setクラスを用いて実装 n = int(input()) s = list(map(int,input().split())) q = int(input()) t = list(map(int,input().split())) temp = …