• 【leetcode❤python】 374. Guess Number Higher or Lower


    #-*- coding: UTF-8 -*-
    # The guess API is already defined for you.
    # @param num, your guess
    # @return -1 if my number is lower, 1 if my number is higher, otherwise return 0
    # def guess(num):
    #binary search
    class Solution(object):
        def guessNumber(self, n):
            """
            :type n: int
            :rtype: int
            """
            left=1;right=n
            while(left<=right):
                mid=(left+right)/2
                res=guess(mid)
                if res==0:
                    return mid
                elif res==-1:
                    right=mid-1
                else:
                    left=mid+1

  • 相关阅读:
    进程
    并发编程
    操作系统的发展史
    __init__、__new__、__call__ 方法
    MongoDB文档操作
    MongoDB集合操作
    MongoDB数据库操作
    MongoDB连接
    MongoDB的文档存储结构
    MongoDB 概念
  • 原文地址:https://www.cnblogs.com/kwangeline/p/6059518.html
Copyright © 2020-2023  润新知