【leetcode】LCP 1. Guess Numbers
题目如下:
小A 和 小B 在玩猜数字。小B 每次从 1, 2, 3 中随机选择一个,小A 每次也从 1, 2, 3 中选择一个猜。他们一共进行三次这个游戏,请返回 小A 猜对了几次?
输入的guess数组为 小A 每次的猜测,answer数组为 小B 每次的选择。guess和answer的长度都等于3。
示例 1:
输入:guess = [1,2,3], answer = [1,2,3]
输出:3
解释:小A 每次都猜对了。示例 2:
输入:guess = [2,2,3], answer = [3,2,1]
输出:1
解释:小A 只猜对了第二次。限制:
guess的长度 = 3
answer的长度 = 3
guess的元素取值为 {1, 2, 3} 之一。
answer的元素取值为 {1, 2, 3} 之一。
解题思路:在leetcode还有比这更简单的题吗?
代码如下:
class Solution(object):
def game(self, guess, answer):
"""
:type guess: List[int]
:type answer: List[int]
:rtype: int
"""
res = 0
for g,a in zip(guess,answer):
if g == a:res += 1
return res
【leetcode】LCP 1. Guess Numbers的更多相关文章
- 【LeetCode】165. Compare Version Numbers 解题报告(Python)
[LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- 【LeetCode】445. Add Two Numbers II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 先求和再构成列表 使用栈保存节点数字 类似题目 日期 ...
- 【leetcode】Bitwise AND of Numbers Range(middle)
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- 【LeetCode】165 - Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...
- 【leetcode】448. Find All Numbers Disappeared in an Array
problem 448. Find All Numbers Disappeared in an Array solution: class Solution { public: vector<i ...
- 【Leetcode】445. Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significan ...
- 【LeetCode】002 Add Two Numbers
题目: You are given two non-empty linked lists representing two non-negative integers. The digits are ...
- 【LeetCode】2.Add Two Numbers 链表数相加
题目: You are given two linked lists representing two non-negative numbers. The digits are stored in r ...
- 【LeetCode】LCP 07. 传递信息
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BFS 日期 题目地址:https://leetcod ...
随机推荐
- beego框架学习(三) -orm的使用
2 3 4 5 6 7 8 9 10 11 目前beego-orm支持的数据有: - MySQL:https://github.com/go-sql-driver/mysql - PostgreSQL ...
- jQuery 获得内容
地址 text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元素的内容(包括 HTML 标记) val() - 设置或返回表单字段的值 一.text() html() &l ...
- 红帽学习笔记[RHCE]OpenLDAP 服务端与客户端配置
目录 OpenLDAP 服务端与客户端配置 关于LDIF 一个LDIF基本结构一个条目 属性 Object的类型 服务端 安装 生成证书 生成默认数据 修改基本的配置 导入基础数据 关于ldif的格式 ...
- pycharm中ctrl + C复制, ctrl+A全选等快捷键失效
原因是:在安装pycharm的时候也同时安装了vim插件,需要在settings - > vim Emulation里将相关的handler改成 IDE
- 【校内test】桶哥的问题
(以上题目出自_rqy两年前) #A:桶哥的问题——买桶[链接] [题目描述] 桶哥要买一些全家桶.他有a元钱,而每个桶要花b元钱.他能不能买到c个桶? [输入格式] 一行三个整数a, b, c [输 ...
- Luogu P2915 [USACO08NOV]奶牛混合起来
题外话: 是非常颓废的博主 写题解也不在于能不能通过啦,主要是缓解颓废 首先看到这个题,肯定是可以暴力搜索的: 不得不说这道题还是很善良的,一波大暴力dfs,居然有70pts: #include< ...
- 洛谷 P2051 中国象棋 题解
题面 状态可能不太好想,设f[i][j][k]表示前i行其中有j行是放一个炮,有k行是放两个炮的合法方案数: 那么: f[i+1][j][k]+=f[i][j][k] 在这一行不放任何棋子: ...
- sql server 获取整数的函数ceiling(x)和floor(x)
--ceiling(x)返回不小于x的最小整数值,floor(x)返回不大于x的最大整数值 示例:select CEILING(-3.35), CEILING(3.35), FLOOR(-3.35), ...
- php框架之laravel
常见问题: 1. 访问网站500错误 这是因为laravel的缓存路径没有找到 laravel缓存文件路径是在 config/cache.php中设置,默认存在storage文件夹中 解决:需要保证s ...
- vue.js(3)--v-bind与v-on
vue中的v-bind与v-on的使用 (1)实例 <!DOCTYPE html> <html lang="en"> <head> <me ...