题目如下:

You have a set of tiles, where each tile has one letter tiles[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: 188

Note:

  1. 1 <= tiles.length <= 7
  2. tiles consists 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的更多相关文章

  1. 【LeetCode】1079. Letter Tile Possibilities 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯 日期 题目地址:https://leetcode ...

  2. LeetCode 1079. Letter Tile Possibilities

    原题链接在这里:https://leetcode.com/problems/letter-tile-possibilities/ 题目: You have a set of tiles, where ...

  3. 【LeetCode】784. Letter Case Permutation 解题报告 (Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 循环 日期 题目地址:https://leet ...

  4. 【LeetCode】17. Letter Combinations of a Phone Number 电话号码的字母组合

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:电话号码, 字母组合,回溯法,题解,leetcode, ...

  5. 【LeetCode】17. Letter Combinations of a Phone Number

    题目: 思路:设置两个List,一个存储当前层,一个存储最终层 public class Solution { public List<String> letterCombinations ...

  6. 【LeetCode】017. Letter Combinations of a Phone Number

    题目: Given a digit string, return all possible letter combinations that the number could represent. A ...

  7. 【LeetCode】双指针 two_pointers(共47题)

    [3]Longest Substring Without Repeating Characters [11]Container With Most Water [15]3Sum (2019年2月26日 ...

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

  9. 【LeetCode】880. Decoded String at Index 解题报告(Python)

    [LeetCode]880. Decoded String at Index 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

随机推荐

  1. docker学习与应用

    概要 众所周知,Docker是当前非常火的虚拟化容器技术,对于它的优势以及使用场景网上的资料非常多,这里我推荐大家去这个网站去详细学习docker. 我这里就写一下作为一名后端开发程序员,自己学习do ...

  2. leetcode-mid-Linked list- 103. Binary Tree Zigzag Level Order Traversal

    mycode 99.24% # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x) ...

  3. RAC容灾演练

    RAC容灾演练:在节点一进行验证:步骤 操作命令关闭步骤 检测RAC集群资源状态 crsctl status resource -t 关闭监听 srvctl stop listener -n < ...

  4. Log4net记录日志到本地或数据库

    OperatorLog /****** Object: Table [dbo].[OperatorLog] Script Date: SET ANSI_NULLS ON GO SET QUOTED_I ...

  5. 十二、python字符串方法汇总

    '''1. index():检测字符串str1中是否包含字符串str2 语法:str1.index(str2,beg,end) str:指定检索的字符串:beg开始的索引,默认为0:end结束的索引, ...

  6. 裸BFS题若干

    1poj 3278 http://poj.org/problem?id=3278 #include<math.h> #include<algorithm> #include&l ...

  7. 关于.NET Core的一些问题和疑惑

    1 为什么会出现.NET Core这个东西?即它为了解决什么问题. .NET Core是NET的ECMA标准的一种新的实现.目前.NET已有Framework,Mono,Unity等实现. 原先所有的 ...

  8. ConcurrentSkipListMap 源码分析

    ConcurrentSkipListMap ConcurrentSkipListMap 能解决什么问题?什么时候使用 ConcurrentSkipListMap? 1)ConcurrentSkipLi ...

  9. 机器学习--如何将NLP应用到深度学习(3)

    数据收集以后,我们下面接着要干的事情是如何将文本转换为神经网络能够识别的东西.   词向量 作为自然语言,只有被数学化才能够被计算机认识和计算.数学化的方法有很多,最简单的方法是为每个词分配一个编号, ...

  10. 16/7/7_PHP-方法重载

    PHP中的重载指的是动态的创建属性与方法,是通过魔术方法来实现的.属性的重载通过__set,__get,__isset,__unset来分别实现对不存在属性的赋值.读取.判断属性是否设置.销毁属性. ...