Skip to content

Instantly share code, notes, and snippets.

@zwongeer
Created April 4, 2022 03:00
Show Gist options
  • Save zwongeer/6874b40835416131d4c3561bb3862532 to your computer and use it in GitHub Desktop.
Save zwongeer/6874b40835416131d4c3561bb3862532 to your computer and use it in GitHub Desktop.
// https://leetcode-cn.com/problems/guess-number-higher-or-lower/
/**
* Forward declaration of guess API.
* @param num your guess
* @return -1 if num is lower than the guess number
* 1 if num is higher than the guess number
* otherwise return 0
* int guess(int num);
*/
class Solution {
public:
int guessNumber(int n) {
return (size_t)partition_point((uint8_t*)1, (uint8_t*)n, [] (const uint8_t& i) {
return guess(size_t(&i)) == 1;
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment