mycode  95.35%

思路:构建字典

class Solution(object):
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
dic = {}
for item in strs:
temp = ''.join(sorted(item))
if temp not in dic:
dic[temp] = [item]
else:
dic[temp].append(item)
return list(dic.values())

下面是list的加法

if temp not in dic:
dic[temp] = [item]
else:
dic[temp] += [item]

    if temp not in dic:
dic[temp] = [item]
else:
dic[temp] += [item]

  

leetcode-mid-array-49 Group Anagrams的更多相关文章

  1. LeetCode - 49. Group Anagrams

    49. Group Anagrams Problem's Link ------------------------------------------------------------------ ...

  2. 49. Group Anagrams - LeetCode

    Question 49. Group Anagrams Solution 思路:维护一个map,key是输入数组中的字符串(根据字符排好序) Java实现: public List<List&l ...

  3. 刷题49. Group Anagrams

    一.题目说明 题目是49. Group Anagrams,给定一列字符串,求同源词(包含相同字母的此)的集合.题目难度是Medium. 二.我的做法 题目简单,就不多说,直接上代码: class So ...

  4. leetcode@ [49] Group Anagrams (Hashtable)

    https://leetcode.com/problems/anagrams/ Given an array of strings, group anagrams together. For exam ...

  5. 【一天一道LeetCode】#49. Group Anagrams

    一天一道LeetCode系列 (一)题目 Given an array of strings, group anagrams together. For example, given: [" ...

  6. [LeetCode] 49. Group Anagrams 分组变位词

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  7. 【LeetCode】49. Group Anagrams 解题报告(Python & Java & C++)

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

  8. 【LeetCode】49. Group Anagrams

    题目: Given an array of strings, group anagrams together. For example, given: ["eat", " ...

  9. [leetcode]49. Group Anagrams变位词归类

    Given an array of strings, group anagrams together. Example: Input: ["eat", "tea" ...

  10. LeetCode OJ 49. Group Anagrams

    题目 Given an array of strings, group anagrams together. For example, given: ["eat", "t ...

随机推荐

  1. [LeetCode] 126. 单词接龙 II

    题目链接 : https://leetcode-cn.com/problems/word-ladder-ii/ 题目描述: 给定两个单词(beginWord 和 endWord)和一个字典 wordL ...

  2. django -----原生SQL语句查询与前端数据传递?

    view.py中 import MySQL def request_data(request): if request.method == "GET": conn = MySQLd ...

  3. Java的同名属性、同名普通函数、同名静态函数,是否被覆盖

    作者按:虚拟函数的概念早就滚瓜烂熟了.但是今天面试发现:1.同名属性,2.同名普通函数,3.同名静态函数,是否被覆盖的问题.请看下面三个例子: 例子1:测试父类的属性是否存在和被完全覆盖class A ...

  4. P2P技术

    1.什么是P2P技术 点对点技术又称对等互联网络技术,是一种网络新技术,依赖网络中参与者的计算能力和带宽,而不是把依赖都聚集在较少的几台服务器上.P2P网络通常用于通过Ad Hoc连接来连接节点. P ...

  5. 流畅的Python (Fluent Python) —— 第二部分01

    2.1 内置序列类型概览 Python 标准库用 C 实现了丰富的序列类型,列举如下. 容器序列 list. tuple 和 collections.deque 这些序列能存放不同类型的数据. 扁平序 ...

  6. Linux系统性能测试工具(四)——CPU性能测试工具之super_pi、sysbench

    本文介绍关于Linux系统(适用于centos/ubuntu等)的CPU性能测试工具-sysbench.CPU性能测试工具包括: super_pi: sysbench——不仅可以测试CPU性能,而且可 ...

  7. mingetty - 控制台最小的 getty

    总览 SYNOPSIS mingetty [--noclear] [--nonewline] [--noissue] [--nohangup] [--nohostname] [--long-hostn ...

  8. Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration

    https://www.cnblogs.com/EasonJim/p/7546136.html 错误如下: ERROR 31473 --- [ main] o.s.b.d.LoggingFailure ...

  9. 连接数据库出现错误:1045-Access denied for user 'root'@'localhost'解决方法

    Navicat for MySQL 链接: https://pan.baidu.com/s/1slwQxVB 密码: r737 1.出现这个问题的原因之一是权限的问题,也就是说你的电脑可能没有权限访问 ...

  10. web页面调用app的方法

    use_app_goto_page: (skip_type, skip_target) => { // Android App if (/android/i.test(navigator.use ...