rewrite leetcode maximum subarray