leetcode374
// Forward declaration of guess API.
// @param num, your guess
// @return -1 if my number is lower, 1 if my number is higher, otherwise return 0
int guess(int num); class Solution {
public:
int guessNumber(int n) {
int i=,j=n;
while(i<j){
int mid=i+(j-i)/;
if(guess(mid)==){
return mid;
}else if(guess(mid)==){
i=mid+;
}else{
j=mid;
}
}
return i;
}
};
https://leetcode.com/problems/guess-number-higher-or-lower/#/description
leetcode374的更多相关文章
- 每天一道LeetCode--374. Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...
- [Swift]LeetCode374. 猜数字大小 | Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...
- LeetCode374 猜数字大小
我们正在玩一个猜数字游戏. 游戏规则如下:我从 1 到 n 选择一个数字. 你需要猜我选择了哪个数字.每次你猜错了,我会告诉你这个数字是大了还是小了.你调用一个预先定义好的接口 guess(int n ...
随机推荐
- UVA-10806 Dijkstra, Dijkstra. (最小费用流,网络流建模)
题目大意:给一张带权简单图,找出一条经过起点s和终点t的最小回路. 题目分析:建立网络,以s为源点,t为汇点,另每条边的容量为1,单位费用为边权值.求最小费用流,增广两次后的最小费用便是答案. 代码如 ...
- UVA-863 Not so Mobile (简单二叉树)
题目大意:给一个树状天平,判断是否平衡.树状天平是按递归给出的. 题目分析:平衡的条件是子天平都平衡,并且w1*d1==w2*d2,其中w1和w2为子天平的总重量,d1和d2为力矩. 代码如下: # ...
- Fly Vim, First-Class
http://corner.squareup.com/2013/08/fly-vim-first-class.html Engineers at Square use a wide variety o ...
- SQLSERVER 数据调度示例,调度数据到中间表或者历史表
USE [MeiDongPay_Test] GO /****** Object: StoredProcedure [dbo].[Job_BatchTransferOrderToMidst] Scrip ...
- 自动化测试--响应请求测试(.net)
Web运行原理简单地说是“浏览器发送一个HTTP Request到Web服务器上,Web服务器处理完后将结果(HTTP Response)返回给浏览器”. 通常测试一个web api是否正确,可以通过 ...
- Winform开发之ADO.NET对象Connection、Command、DataReader、DataAdapter、DataSet和DataTable简介
ADO.NET技术主要包括Connection.Command.DataReader.DataAdapter.DataSet和DataTable等6个对象,下面对这6个对象进行简单的介绍:(1)Con ...
- 重写ajax方法实现特定情况下跳转登录页面
jQuery(function($){ // 备份jquery的ajax方法 var _ajax=$.ajax; // 重写ajax方法, $.ajax=function(opt){ var _suc ...
- ZetCode PyQt4 tutorial custom widget
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- opencv之批量转换灰度图并保存
当图片名字有数字规律时,批量处理方式. ①srcImage 图片名字有规律 ②将srcImage文件下的图片,转换为灰度图并保存入grayImage文件夹. ③ #include <iostre ...
- InputStream,String和Reader之间的转换
1.String –> InputStreamInputStrem is = new ByteArrayInputStream(str.getBytes());orByteArrayInputS ...