guess

LeetCode374. 猜数字大小 --数组--二分法--简单

瘦欲@ 提交于 2020-01-22 23:07:27
题目描述: 我们正在玩一个猜数字游戏。 游戏规则如下: 我从 1 到 n 选择一个数字。 你需要猜我选择了哪个数字。 每次你猜错了,我会告诉你这个数字是大了还是小了。 你调用一个预先定义好的接口 guess(int num),它会返回 3 个可能的结果(-1,1 或 0): -1 : 我的数字比较小 1 : 我的数字比较大 0 : 恭喜!你猜对了! 示例 : 输入: n = 10, pick = 6 输出: 6 参考链接: https://leetcode-cn.com/problems/guess-number-higher-or-lower 解题思路: 1、暴力破解 //暴力破解法 /* The guess API is defined in the parent class GuessGame. @param num, your guess @return -1 if my number is lower, 1 if my number is higher, otherwise return 0 int guess(int num); */ //java public class Solution extends GuessGame { public int guessNumber(int n) { for (int i = 1; i < n; i++) if (guess

20200121-LC-Can You Guess the Secret?

我是研究僧i 提交于 2020-01-22 01:22:07
Today, I'm very happy. I meet the new friend. We write the story together. Today, is the latest day of work for my colleague. We take the selfie,haha. Today, is Tuesday. I install the mysql databases so many time, so I know how to install. Sometime is the configurationfile's problem. Sometime is the synchronization's problem. Now is the synchronization problem. I reboot the database, but it doesn't synchronization again. Tomorrow is my latest day of 2019's(China day) for work. I will work half of the day. Then I plan to study English. I have 2 lesson. This spring festival I plan to study 6

\"Hello_Python\"_基础语法1

拥有回忆 提交于 2020-01-21 16:19:13
变量 变量定义 变量名只能是字母、数字或下划线的任意组合 变量名的第一个字符不能是数字 关键字不能声明为变量名 ['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield'] # 动态语言变量定义时不需要指明变量的数据类型 # 字符串类型变量可以使用""或'',""和''在Python中没有区别,不加""或''的字符串系统默认为变量名 name = "young" age = 25 print("My name is", name, "...I'm", age, "years old!") 输出结果如下: My name is young ...I'm 25 years old! Python中没有常量的概念,如果需要表示某一固定不变的量,例如数学中的π,一般习惯将变量名全大写表示: PIE = 3.1415926 当变量被定义时

1

半世苍凉 提交于 2020-01-20 21:51:10
创建一个 Pure Python 3.5,2 New directory 目录 创建一个程序 声明一个解释器 Vietw File and Code Templates 写程序 运行print("hello world ")右击 变量 什么是变量?变量是用来干嘛的? 变量是用来存东西的,存东西是为了以后来调用的。 不存就被内存释放了。存在内存里。 怎么定义一个变量name ="Alex Li" c++string name ="Alex Li" #调用 print(“My name is”,name)??My name is Alex Li name = "Alex Li" name2 = name print("My name is ",name ,name2) name="PaoChe Ge" print(name,name2) ?? Alex Li PaoChe Ge name 本来指向的是“Alex Li” name2指向的是name指向的(name只是向name2指一条路,name2并不会随着name的改变而改变。) 标识符 数字、字母、下划线 首字符不能是数字 约定俗成 变量名一定要能看懂(虽然Python能是中文执行但是千万不要去用) gf_of_oldboy="chen rong hua" 变量 常量 在Python里是没有这个概念的 若想要定义一个常量

python基础一

喜欢而已 提交于 2020-01-19 12:35:50
一、简介 1、编译型语言 写好代码之后,把代码编译成二进制文件,运行的时候运行编译好的二进制文件 例如:c,c++,c# 优点:速度快,一次编译,到处运行 缺点:编译过程慢 2、解释性语言(运行速度没有编译型语言快) 运行一行代码编译一行,什么时候运行代码,什么时候编译代码 例如:php ,python, ruby,java,go,JavaScript 缺点:运行速度比较慢 3、脚本语言 功能单一的语言,叫脚本语言 例如:shell,bat,JavaScript,html,vb 4、python可用于:后台服务开发,数据挖掘,数据分析,人工智能,自动化运维,自动化测试 二、变量 1、定义变量是为了后面还要用到它的值 2、编程都是和内存打交道的 3、既有单引号又有双引号,则用''' ''' 4、单行注释用# 5、多行注释用成对的三个单引号''' ''' 6、以下单词,定义变量时不能用:'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except','exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print',

Python手写数字识别之路1

若如初见. 提交于 2020-01-16 00:52:54
Python入门 虽然Python是从C语言发展而来,但是我觉得和c语言区别巨大。 首先玩一个小游戏 guess "python" import random counts = 3 answer = random . randint ( 1 , 10 ) #生成一个随机数,guess while counts > 0 : temp = input ( "enter number " ) guess = int ( temp ) if guess == answer : print ( "right" ) break else : if guess < answer : print ( "small" ) else : print ( "big" ) counts = counts - 1 print ( "game over" ) for member = [ '小明' , '弱音' , '狂三' , '光辉' ] for i in member : print ( i , len ( i ) ) for i in range ( 0 , 20 , 3 ) : # 步进为3 print ( i ) white while TURE : code list member = [ '小明' , '弱音' , '狂三' , '光辉' ] for i in member : print (

kaggle-titanic 数据分析过程

不打扰是莪最后的温柔 提交于 2020-01-13 14:39:48
1. 引入所有需要的包 # -*- coding:utf-8 -*- # 忽略警告 import warnings warnings.filterwarnings('ignore') # 引入数据处理包 import numpy as np import pandas as pd # 引入算法包 from sklearn.tree import DecisionTreeClassifier from sklearn.linear_model import LogisticRegression from sklearn.neighbors import KNeighborsClassifier from sklearn.naive_bayes import GaussianNB from sklearn.ensemble import BaggingRegressor from sklearn.svm import SVC, LinearSVC from sklearn.ensemble import RandomForestClassifier,GradientBoostingClassifier from sklearn.ensemble import GradientBoostingRegressor from sklearn.linear_model import

if_while

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-07 04:14:03
import random secret=random.randint(1,10) tmp=input("请输入一个数") guess=int(tmp) while guess!=secret: tmp=input("请输入一个数") guess=int(tmp) if guess==secret: print("bingo") else: if guess>secret: print("大了") else: print("小了") print("游戏结束")  ①random.randint(1,10)生成一个1~10的数。 来源: https://www.cnblogs.com/KIROsola/p/12154536.html

while循环,for循环

大兔子大兔子 提交于 2020-01-03 03:59:25
age_of_oldboy = 56 count = 0 while count <3: guess_age = int(input("guess age:")) if guess_age == age_of_oldboy: print("yes,you got it.") break elif guess_age > age_of_oldboy: print("think smaller...") else: print("think bigger....") count +=1 优化后的代码: age_of_oldboy = 56 count = 0 while count <3: guess_age = int(input("guess age:")) if guess_age == age_of_oldboy: print("yes,you got it.") break elif guess_age > age_of_oldboy: print("think smaller...") else: print("think bigger....") count +=1 else: print("you have tried too mant times...fuck off") for循环的代码: age_of_oldboy = 56 count = 0 for i in