マツシタのお勉強

いもす法

3Sum Closest : LeetCode

Problem leetcode.com 与えられたInt型の配列numsの要素の内、3つ選んだ要素の和がtargetに最も近い値を見つける問題。 Solution 全列挙によるO(N3)の解法 配列の全ての3つの要素の和を算出し、その中から一番targetに近い値を見つける事で問題を解くこと…

Find All Anagrams in a String: Amazon

Problem Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s. Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100. The order of outp…

いもす法を用いて計算量をO(N^2)からO(N)に減らす

いもす法について整理します。 問題 AtCoder ABC 014 C C: AtColor - AtCoder Beginner Contest 014 | AtCoder ソースコード 解説 まずは普通の解き方を見てみる。 いもす法使わない解法 これは、それぞれのアンケートに対して、その解答で得られた範囲の分…