【leetcode❤python】 299. Bulls and Cows
#-*- coding: UTF-8 -*-
class Solution(object):
def getHint(self, secret, guess):
"""
:type secret: str
:type guess: str
:rtype: str
"""
countA,i,numList=0,-1,[[0,0] for j in range(10)]
print numList
while 1:
i+=1
try:
if secret[i]==guess[i]:countA+=1
else:
numList[int(secret[i])][0]+=1
numList[int(guess[i])][1]+=1
except:
break
return "%sA%sB"%(countA,sum(min(i,v) for i,v in numList))
【leetcode❤python】 299. Bulls and Cows的更多相关文章
- 【leetcode❤python】299. Bulls and Cows
class Solution(object): def getHint(self, secret, guess): """ :type ...
- 【LeetCode】299. Bulls and Cows 解题报告(Python)
[LeetCode]299. Bulls and Cows 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题 ...
- 【一天一道LeetCode】#299. Bulls and Cows
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 You are ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 【leetcode】299. Bulls and Cows
题目如下: 解题思路:本题难度不太大,对时间复杂度也没有很高的要求.我的做法是用一个字典来保存每个字符出现的次数,用正数1记录标记secret中出现的字符,用负数1记录guess中出现的字符,这样每出 ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
- 【leetcode❤python】 58. Length of Last Word
#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object): ...
- 【leetcode❤python】 8. String to Integer (atoi)
#-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...
- 【leetcode❤python】 165. Compare Version Numbers
#-*- coding: UTF-8 -*-class Solution(object): def compareVersion(self, version1, version2): ...
随机推荐
- test generation和MBIST
The problem of test generation Random test generation Deterministic algorithm for test generation fo ...
- JSP-05- JSP总结
1 客户端请求新页面 <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- 用VS2010编C#程序扫盲 2
0.正则表达式:http://www.runoob.com/csharp/csharp-regular-expressions.html 1.异常处理: try { // 引起异常的语句 } catc ...
- 批量修改照片名称的shell脚本
代码这种经常完善的东西,其实是不太适合使用博客来发布的. 以下是一个批量修改照片名称的shell脚本: 事情是这样的,虽然手机拍的照片文件名是按照日期来确定的,但是是这种形式的 IMG_mmddYY_ ...
- 【crunch bang】文件管理器-thunar
Thunar拥有的实用功能: 缩略图查看 批量重命名 安装: $ sudo apt-get install thunar 加速thunar启动速度 sudo leafpad /usr/share/gv ...
- 【python cookbook】【数据结构与算法】4.找到最大或最小的N个元素
问题:想在某个集合中找出最大或最小的N个元素 解决方案:heapq模块中的nlargest()和nsmallest()两个函数正是我们需要的. >>> import heapq &g ...
- 160918、BigDecimal运算
java.math.BigDecimal.BigDecimal一共有4个够造方法,让我先来看看其中的两种用法: 第一种:BigDecimal(double val)Translates a doubl ...
- TI CC2541的中断优先级设置.
实际看到的中断优先级设置是这样的:
- linux配置java环境变量(详细)【转】
转自:http://www.cnblogs.com/samcn/archive/2011/03/16/1986248.html 一. 解压安装jdk 在shell终端下进入jdk-6u14-linux ...
- [转]System.Reflection.AssemblySignatureKeyAttribute
转自:http://www.cnblogs.com/ego/p/3321122.html 错误: Could not load type 'System.Reflection.AssemblySign ...