我做过的第一个 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的更多相关文章

  1. [LeetCode] 843. Guess the Word 猜单词

    This problem is an interactive problem new to the LeetCode platform. We are given a word list of uni ...

  2. [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 ...

  3. [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  4. [LeetCode] Length of Last Word 求末尾单词的长度

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  5. LeetCode——Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  6. [LeetCode] Stickers to Spell Word 贴片拼单词

    We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...

  7. 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 ...

  8. LeetCode算法题-Longest Word in Dictionary(Java实现)

    这是悦乐书的第303次更新,第322篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第171题(顺位题号是720).给出表示英语词典的字符串单词数组,找到单词中长度最长的单 ...

  9. [leetcode]Length of Last Word @ Python

    原题地址:https://oj.leetcode.com/problems/length-of-last-word/ 题意: Given a string s consists of upper/lo ...

随机推荐

  1. HTML中使用js的三种方式及优缺点介绍

    1.内部js: 在直接在页面的<script></script>标签内写js代码 优点:相对于使用行内js,内部js代码较为集中,与页面结构的实现代码耦合度较低,比较便于维护 ...

  2. 2018-8-10-win10-uwp-打开文件管理器选择文件

    title author date CreateTime categories win10 uwp 打开文件管理器选择文件 lindexi 2018-08-10 19:16:50 +0800 2018 ...

  3. Linux-c对一个十六进制数的某一位取反

    enum SWITCH_FLAG { SWITCH_ALL_FLAG = , SWITCH_WEB_FLAG = , …… } unsigned int switch_by_bit_value = 0 ...

  4. 233 Matrix

    233 Matrix 有一\(n\times m\)的矩阵\(\{a\}\),定义\(a[0][0]=0,a[0][1]=233,a[0][2]=2333,a[0][3]=23333...\),然后给 ...

  5. data hazard in CPU pipeline

    1, background info 5 stages in CPU pipeline: IF, ID, EX, MM, WB IF – Instruction Fetch ID – Instruct ...

  6. android Serializable 和 Parcelable 区别

      android 中自定义的对象序列化的问题有两个选择一个是Parcelable,另外一个是Serializable. 一 序列化原因: 1.永久性保存对象,保存对象的字节序列到本地文件中:2.通过 ...

  7. idea配置tomcat中war和war exploded的区别

    是选择war还是war exploded 这里首先看一下他们两个的区别: war模式:将WEB工程以包的形式上传到服务器 :war exploded模式:将WEB工程以当前文件夹的位置关系上传到服务器 ...

  8. Python学习day14-函数进阶(2)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  9. Starting MySQL ** mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists

    本地虚拟机(CentOS6.8)启动MySQL(MySQL5.6.35)服务失败 [root@VMUest ~]# service mysql status ERROR! MySQL is not r ...

  10. C开发系列-函数

    概述 任何一个C语言程序都是有一个或多个程序段(小程序构成).每个程序都有自己的功能,我们一般称这些程序段为"函数". 函数的执行过程 #import <Foundation ...