rewrite leetcode search a 2d array