【leetcode❤python】299. Bulls and Cows
class Solution(object):
def getHint(self, secret, guess):
"""
:type secret: str
:type guess: str
:rtype: str
"""
countA,i,numList=0,-1,[[0,0] for i in range(10)]
while True:
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
#-*- coding: UTF-8 -*-class Solution(object): def getHint(self, secret, guess): " ...
- 【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): ...
随机推荐
- FM000
SQL> select To_char(1,'000') from dual; TO_C----001 注意最左边有一个空格 SQL> select To_char(1,'FM000') ...
- Trace Sys
ARM片上调试和跟踪解决方案(包括CoreSight体系结构,嵌入式跟踪宏单元(ETM),程序流程跟踪(PTM),ARM调试接口(ADI), 跟踪缓冲器(ETB),嵌入式交叉触发器(CTM)) Cor ...
- [slim] Slim - Faster, lightweight, a enginer for Ruby
URL: http://slim-lang.com/ Example: doctype html html head title Slim Examples meta name="keywo ...
- Atom 和 Sublime Text 相比哪个好?
好像截止到今天还分不出来,Sublime确实会快一点.
- resultMap / resultType
===================resultMap:实体类的属性和通过resultMap映射后的property属性一致 <resultMap id="workerSelect& ...
- Java中多线程使用匿名内部类的方式进行创建3种方式
/* * 匿名内部类的格式: */ public class ThreadDemo { public static void main(String[] args) { // 继承thread类实现多 ...
- C/C++的一些备忘
今天使用source insight阅读videoserver源码,有一些符号ctrl+左键点击显示找不到,先是rebuild工程和同步,没有效果,然后Options->Preferences- ...
- [BIM]BIM中IFD介绍
第三大支柱IFD - 确定交换的信息和你要的信息是同一个东西 IFD的全称是International Framework for Dictionaries,中文可以叫“国际字典框架”,和前两者IFC ...
- CSS select样式列表-------美化列表
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- API判断网站IP地址,国家区域
直接访问http://api.wipmania.com/jsonp 还有经纬度