注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
Twitter OA:
(1)
Twosum from Leetcode
第一題上 Leetcode 看
(2)
You are given a binary array with N elements: d[0], d[1], ... d[N - 1].
You can perform AT MOST one move on the array: choose any two integers [L, R], and flip all the elements between (and including) the L-th and R-th bits. L and R represent the left-most and right-most index of the bits marking the boundaries of the segment which you have decided to flip.
What is the maximum number of '1'-bits (indicated by S) which youesToFlip = currentOnesToFlip;
} else if (currentDiff > 0) {
currentDiff = 0;
currentStart = i + 1;
currentOnesToFlip = 0;
}
}
System.out.println(flipEndIndex - flipStartIndex + 1 - onesToFlip + totalNumberOfOnes - onesToFlip);
}
Space O(1), Time O(n)
|