我做过的第一个 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. MySQL 调优/优化的 101 个建议!

    原文:http://www.monitis.com/blog/101-tips-to-mysql-tuning-and-optimization/ MySQL是一个强大的开源数据库.随着MySQL上的 ...

  2. 19.SimLogin_case07

    # 模拟登录豆瓣 from urllib.request import urlretrieve import requests from bs4 import BeautifulSoup from o ...

  3. Mybatis-generator/通用Mapper/Mybatis-Plus对比

    mybatis-plus-boot-starter和mybatis-spring-boot-starter冲突导致MapperScan失效问题还没有解决,只能不用mybatis-plus-boot-s ...

  4. ListControl 设置表格行高与字体

    设置行高: CImageList   m_l;  m_l.Create(1,18,TRUE|ILC_COLOR32,1,0);   listCtrl.SetImageList(&m_l,LVS ...

  5. 中国剩余定理模数互质的情况模板(poj1006

    http://poj.org/problem?id=1006 #include <iostream> #include <cstdio> #include <queue& ...

  6. WPF 深入浅出学习 Day1

  7. 模拟——1031D

    /* dp[i][j]表示到[i,j]的权值 cnt[i,j]表示到[i,j]还可以使用的修改的次数 cnt[i,j]=max(cnt[i-1,j],cnt[i,j-1]) 如果mp[i,j]!='a ...

  8. C++内存字节对齐规则

    为什么要进行内存对齐以及对齐规则 C/C++—— 内存字节对齐规则 C++内存字节对齐规则

  9. 解决无法wifi上网的问题

    1.查看网卡型号 lspci | grep Network 可以看到我的是Wireless-AC 9560 2.登录Inter官网下载网卡驱动 https://www.intel.com/conten ...

  10. JS 作用域、原型链

    看到一道好题,并附答案 function Foo() { getName = function () { console.log('1'); }; return this; } Foo.getName ...