题目要求

You are given an array A of strings.

Two strings S and T are special-equivalent if after any number of moves, S == T.

A move consists of choosing two indices i and j with i % 2 == j % 2, and swapping S[i] with S[j].

Now, a group of special-equivalent strings from A is a non-empty subset S of A such that any string not in S is not special-equivalent with any string in S.

Return the number of groups of special-equivalent strings from A.

题目分析及思路

给定一组字符串,若经过若干次move两个字符串相等,则这两个字符串是special-equivalent。定义一次move是将字符串中的奇数或偶数位置的两个字母交换。题目要求返回这一组字符串的special-equivalent字符串的组数。可以分别对每一个字符串的奇数和偶数位置的字母进行排序再合并,最后将合并的结果放入集合中,集合的长度即为所求。

python代码

class Solution:

def numSpecialEquivGroups(self, A: 'List[str]') -> 'int':

s = set()

for a in A:

s.add(''.join(sorted(a[0::2]))+''.join(sorted(a[1::2])))

return len(s)

转载于:https://www.cnblogs.com/yao1996/p/10401205.html

LeetCode 893 Groups of Special-Equivalent Strings 解题报告相关推荐

  1. 【LeetCode】222. Count Complete Tree Nodes 解题报告(Python)

    [LeetCode]222. Count Complete Tree Nodes 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个 ...

  2. [LeetCode]849. Maximize Distance to Closest Person 解题报告(C++)

    [LeetCode]849. Maximize Distance to Closest Person 解题报告(C++) 题目描述 In a row of seats, 1 represents a ...

  3. [leetcode] 893. Groups of Special-Equivalent Strings

    题目: You are given an array A of strings. Two strings S and T are special-equivalent if after any num ...

  4. [LeetCode] Multiply Strings 解题报告

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  5. 【LeetCode】954. Array of Doubled Pairs 解题报告(Python)

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

  6. 【LeetCode】328. Odd Even Linked List 解题报告(Python C++)

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

  7. 【LeetCode】825. Friends Of Appropriate Ages 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/friends-o ...

  8. 【LeetCode】528. Random Pick with Weight 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/random-pi ...

  9. Leetcode 389. Find the Difference 找不同 解题报告

    1 解题思想 有两个字符串S和T,T是S打乱后多加一个字符,要找出这个不同的字符来. 嗯,这个问题其实就是异或,除了T多的那个字符外,都可以在异或中消除,不多说,很简单 2 原题 Given two ...

  10. [Leetcode] 33. Search in Rotated Sorted Array 解题报告

    题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7  ...

最新文章

  1. python字典相同key的值怎么分别取出_python字典值排序并取出前n个key值的方法
  2. 文巾解题 203. 移除链表元素
  3. springcloud 服务网关Zuul实战(二)路由访问映射规则
  4. Python IDLE换行写,一行写不下,如何换行继续写
  5. ubuntu中安装sqldeveloper和JDK 1.7
  6. oracle分区表 mysql_Oracle分区表的使用和管理
  7. 客快物流大数据项目(二):物流项目详细介绍
  8. GJB 5000A与GJB 5000B区别
  9. PXE工作流程(PXE启动报错处理)
  10. 华为手机主界面的返回键怎么调出来_华为手机怎么调出来下面返回键
  11. Floyd Thomas - Principles of Electric Circuits_ Conventional Current-Pearson (2021) 电路基础书籍推荐
  12. Kindle使用的一些方法
  13. 米斯齐超声波传感器显示测量距离(oled)内附Arduino代码
  14. 6种品牌打印机介绍及打印机旗舰店推荐
  15. 为什么Lisp如此先进,却永远成为不了编程主流语言?深度解析Lisp的优势与劣势
  16. c语言 inc文件夹,汇编 inc 和 dec 指令
  17. python从属关系编号_42:对象、类、以及从属关系
  18. 企企通:企业供应商风险管理,如何用采购管理软件赋能?
  19. Win10去除快捷方式的小箭头
  20. 中国石油大学浏览器 服务器系统,中国石油大学信息中心

热门文章

  1. ubuntu使用笔记一
  2. leetcode/剑指Offer05.替换空格 双指针法实现原地替换
  3. 苹果Mac上好用的分屏软件:Magnet
  4. 如何在 Mac 上的 Pages 文稿中格式化文本栏?
  5. 如何在 Mac 上进行屏幕录制?
  6. 可以修改Mac地址的工具WiFiSpoof for Mac
  7. Find Any File for Mac(本地文件搜索查找工具)
  8. DMG Canvas for mac(DMG打包工具)
  9. Mac中将 WEBP 图片转成 JPG、PNG 格式的 2 种方法
  10. 如何在macOS中得到“另存为”快捷方式