← 返回 walmartlabs 的题目列表Find the First Corrupted Character
类型:online_judge
Given an array of characters where a method isCorrupted(char c) returns true if a character is corrupted:
If one character is corrupted, all following characters are also corrupted.
Find the first corrupted character efficiently.
Input
chars: An array of characters, with a maximum length of 10^6.
isCorrupted(char c): A method that returns whether a character is corrupted.
Output
Return the first corrupted character.
Example
Input: chars = ['a', 'b', 'c', 'x', 'y'], assume isCorrupted('x') = true
Output: 'x'
Constraints
Time Complexity: The optimal solution should have a time complexity of O(log n)
Example
Input
a b c d x y