rewrite leetcode search in a rotated sorted array