leetcode 843. Guess the Word
我做过的第一个 interactive problem
给一个候选词列表,每次猜测可以猜里面的词,会返回猜中匹配的个数,
可以猜10次,
加上随机化策略之后几乎可以一定通过测试(尽管不是100%)
class Solution:
def findSecretWord(self, wordlist, master):
"""
:type wordlist: List[Str]
:type master: Master
:rtype: None
"""
def similar(X,Y):
return sum([X[i]==Y[i] for i in range(len(X))])
flag=False
guess_dict={}
random.shuffle(wordlist)
while(not flag):
for guess_word in wordlist:
guess=True
for guessed_word in guess_dict:
if similar(guessed_word,guess_word)!=guess_dict[guessed_word]:
guess=False
break
if guess:
print(guess_word)
guess_num=master.guess(guess_word)
if(guess_num==len(guess_word)):
flag=True
guess_dict[guess_word]=guess_num
break
leetcode 843. Guess the Word的更多相关文章
- [LeetCode] 843. Guess the Word 猜单词
This problem is an interactive problem new to the LeetCode platform. We are given a word list of uni ...
- [LeetCode] Maximum Product of Word Lengths 单词长度的最大积
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
- [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- [LeetCode] Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- LeetCode——Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- [LeetCode] Stickers to Spell Word 贴片拼单词
We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...
- LeetCode之“动态规划”:Word Break && Word Break II
1. Word Break 题目链接 题目要求: Given a string s and a dictionary of words dict, determine if s can be seg ...
- LeetCode算法题-Longest Word in Dictionary(Java实现)
这是悦乐书的第303次更新,第322篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第171题(顺位题号是720).给出表示英语词典的字符串单词数组,找到单词中长度最长的单 ...
- [leetcode]Length of Last Word @ Python
原题地址:https://oj.leetcode.com/problems/length-of-last-word/ 题意: Given a string s consists of upper/lo ...
随机推荐
- Java基础:基本类型
1.基本类型 Java中有8种基本类型,分为4类,分别为: 整型:包括 byte . short. int . long 泛型:float.double 字符型:char 布尔型:boolean 2 ...
- Activiti学习笔记2 — HelloWorld
一. Maven的POM配置文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="htt ...
- 微软云数据库SQL Azure
- linux普通用户无法登录mysql
一.前言 本帖方法只适用于普通用户无法登录,但root用户可以登录的情况. 今天将war包放入linux后,运行报错,经过检查发现是数据库连接不上.奇怪的是,用户名和密码都是正确的,所以有了以下发现. ...
- CF755F PolandBalls and Gifts
题意:给你一个礼物的置换.有k个人忘带了礼物.一个人无法获得礼物为他自己没有带礼物或给他带礼物的那个人没有带礼物.求选择k个人,没有获得礼物的人数的最小值和最大值. n,k<=1e6. 标程: ...
- 修改Apache的默认站点目录的方法,需要的朋友可以参考下
由于博客系统崩了,所以要考虑重新建立博客系统,首先遇到的一个问题就是原来的博客系统是安装一个独立的磁盘上面的(http://m.0834jl.com)不是安装在系统盘上面的,然而一般在linux下面安 ...
- DRF 序列化组件单增
目录 自定义序列化(矬) Serializer类(方式繁琐) 底层序列化类 UserSerializer 视图序列化步骤 底层反序列化类 UserCreatSerializer 视图反序列化步骤 Mo ...
- 思维构造,建图——cf1159E
很好的题 /* nexti:pi右边第一个比pi大的数的下标 把每个[i,a[i]]都看成一段区间,区间只能在端点处交叉,以此来判断是否有解 特别的,如果a[i]=-1,那么把a[i]=i+1,不对其 ...
- LUOGU P3387 【模板】缩点 (缩点+DAG dp)
解题思路 缩点后按拓扑排序跑一个dp. #include<iostream> #include<cstdio> #include<cstring> #include ...
- 洛谷 P1242 新汉诺塔
原题链接 题目描述 设有n个大小不等的中空圆盘,按从小到大的顺序从1到n编号.将这n个圆盘任意的迭套在三根立柱上,立柱的编号分别为A.B.C,这个状态称为初始状态. 现在要求找到一种步数最少的移动方案 ...