【leetcode】1079. Letter Tile Possibilities
题目如下:
You have a set of
tiles, where each tile has one lettertiles[i]printed on it. Return the number of possible non-empty sequences of letters you can make.Example 1:
Input: "AAB"
Output: 8
Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".Example 2:
Input: "AAABBC"
Output: 188Note:
1 <= tiles.length <= 7tilesconsists of uppercase English letters.
解题思路:tiles的最大长度是7,那么理论上最多有7!种组合,这个数量非常小,可以全排列所有的的可能性然后过滤重复的数据。
代码如下:
class Solution(object):
def numTilePossibilities(self, tiles):
"""
:type tiles: str
:rtype: int
"""
import itertools
l = range(len(tiles))
dic = {}
for i in range(1,len(l) + 1):
for j in itertools.permutations(l, i):
v = ''
for k in j:
v += tiles[k]
if v not in dic:dic[v] = 1
return len(dic)
【leetcode】1079. Letter Tile Possibilities的更多相关文章
- 【LeetCode】1079. Letter Tile Possibilities 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯 日期 题目地址:https://leetcode ...
- LeetCode 1079. Letter Tile Possibilities
原题链接在这里:https://leetcode.com/problems/letter-tile-possibilities/ 题目: You have a set of tiles, where ...
- 【LeetCode】784. Letter Case Permutation 解题报告 (Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 循环 日期 题目地址:https://leet ...
- 【LeetCode】17. Letter Combinations of a Phone Number 电话号码的字母组合
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:电话号码, 字母组合,回溯法,题解,leetcode, ...
- 【LeetCode】17. Letter Combinations of a Phone Number
题目: 思路:设置两个List,一个存储当前层,一个存储最终层 public class Solution { public List<String> letterCombinations ...
- 【LeetCode】017. Letter Combinations of a Phone Number
题目: Given a digit string, return all possible letter combinations that the number could represent. A ...
- 【LeetCode】双指针 two_pointers(共47题)
[3]Longest Substring Without Repeating Characters [11]Container With Most Water [15]3Sum (2019年2月26日 ...
- 【leetcode】955. Delete Columns to Make Sorted II
题目如下: We are given an array A of N lowercase letter strings, all of the same length. Now, we may cho ...
- 【LeetCode】880. Decoded String at Index 解题报告(Python)
[LeetCode]880. Decoded String at Index 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
随机推荐
- C++类前置声明
cpp前置声明: 前置声明只能作为指针或引用,不能定义类的对象,也不能调用对象中的方法. 详见:https://www.cnblogs.com/dobben/p/7440745.html
- Delphi XE2 之 FireMonkey 入门(22) - 数据绑定: BindingSource、BindingName、FindBinding()、Binding[]
在窗体上添加 TrackBar1.Edit1.Label1, 然后设置属性(可在设计时): procedure TForm1.FormCreate(Sender: TObject); begin ...
- 阶段1 语言基础+高级_1-3-Java语言高级_1-常用API_1_第7节 Arrays工具类_16_数组工具类Array
在java.util的包下面.在这个包的下面是需要导包的,只有lang 的包下面是不需要导包的 查看jdk1.6的手册 Arrays让我们想起了数组,说明它提供了与数组相关的方法 我们可以看到 toS ...
- 阶段1 语言基础+高级_1-3-Java语言高级_04-集合_08 Map集合_2_Map常用子类
常用的实现类HashMap 它的子类.LinkedHaspMap
- http://blog.csdn.net/sdksdk0/article/details/50749326
http://blog.csdn.net/sdksdk0/article/details/50749326
- maven(一) maven到底是什么
为了方便自己查找,这里转载他人文章,原文出处http://www.cnblogs.com/whgk/p/7112560.html 我记得在搞懂maven之前看了几次重复的maven的教学视频.不知道是 ...
- C++[Tarjan求点双连通分量,割点][HNOI2012]矿场搭建
最近在学图论相关的内容,阅读这篇博客的前提是你已经基本了解了Tarjan求点双. 由割点的定义(删去这个点就可使这个图不连通)我们可以知道,坍塌的挖煤点只有在割点上才会使这个图不连通,而除了割点的其他 ...
- C语言1-2019级秋季作业第一周作业
1.你对软件工程专业或者计算机科学与技术专业了解是怎样? 软件工程专业是指对计算机的软件方面灵活掌控,开发软件的工程.软件工程其中会用到计算机科学.数学方面构建模型与算法:软件工程的目标就是开发出能够 ...
- 一次特殊的“VARCHAR转numeric失败”错误记录
今天接触到一个很有意思的问题.当我在执行一条INSERT的sql语句时,他总是报字符串转数字类型失败. 问题 首先,该表中的所有数字类型的字段都是非必填,其次,每个数字类型的字段都有默认值.最令我感到 ...
- [19/05/15-星期三] HTML_body标签(超链接标签和锚点)
一.超链接标签 <html> <head> <meta charset="UTF-8"> <title>04 body超链接标签学习 ...