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 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)
LeetCode 893 Groups of Special-Equivalent Strings 解题报告的更多相关文章
- 【LeetCode】813. Largest Sum of Averages 解题报告(Python)
		
[LeetCode]813. Largest Sum of Averages 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
 - 【LeetCode】522. Longest Uncommon Subsequence II 解题报告(Python)
		
[LeetCode]522. Longest Uncommon Subsequence II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemin ...
 - 【LeetCode】697. Degree of an Array 解题报告
		
[LeetCode]697. Degree of an Array 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/degree- ...
 - 【LeetCode】779. K-th Symbol in Grammar 解题报告(Python)
		
[LeetCode]779. K-th Symbol in Grammar 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingz ...
 - 【LeetCode】792. Number of Matching Subsequences 解题报告(Python)
		
[LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
 - 【LeetCode】881. Boats to Save People 解题报告(Python)
		
[LeetCode]881. Boats to Save People 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu ...
 - 【LeetCode】802. Find Eventual Safe States 解题报告(Python)
		
[LeetCode]802. Find Eventual Safe States 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemi ...
 - 【LeetCode】166. Fraction to Recurring Decimal 解题报告(Python)
		
[LeetCode]166. Fraction to Recurring Decimal 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingz ...
 - 【LeetCode】556. Next Greater Element III 解题报告(Python)
		
[LeetCode]556. Next Greater Element III 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人 ...
 - 【LeetCode】880. Decoded String at Index 解题报告(Python)
		
[LeetCode]880. Decoded String at Index 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
 
随机推荐
- 【WPF】ListBox GridViewColumn Header 文字换行、文字多行显示
			
ListBox GridViewColumn Header 文字换行.文字多行显示,在Header中需要换行的地方写 <GridViewColumn Header="空间另存 为总量& ...
 - Jquery计算指定日期加上多少天、加多少月、加多少年的日期
			
/* * 功能:实现VBScript的DateAdd功能. * 参数:interval,字符串表达式,表示要添加的时间间隔. * 参数:number,数值表达式,表示要添加的时间间隔的个数. * 参数 ...
 - Web - JSONP和同源策略漫谈
			
0x00 前言 关于JSONP网上有很多文章了,我也是在拜读了别人的文章的基础上来写写自己的看法,这样可以加深自己印象,巩固一下学习效果.我们需要做的就是站在巨人的肩膀上眺望远方. 0x01 起 在W ...
 - Linux(C/C++)下的文件操作open、fopen与freopen
			
open是linux下的底层系统调用函数, fopen与freopen c/c++下的标准I/O库函数,带输入/输出缓冲. linxu下的fopen是open的封装函数,fopen最终还是要调用底层的 ...
 - Linux软件源
			
Kali科大软件源: vim /etc/apt/sources.list 下面的粘帖进去. deb http://mirrors.ustc.edu.cn/kali kali main non-free ...
 - js实现滑动的弹性导航
			
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
 - phpstrom2018
			
http://www.oyksoft.com/soft/40722.html?pc=1
 - iOS开发-- 开发中遇到的问题汇总
			
1. CUICatalog: Invalid asset name supplied: 今天写了加载图片,默认图片写的是[UIImage imageNamed:@""],之后就报下 ...
 - 自己的memcache类
			
Mem类代码: class Mem { //类型是memcache或memcached private $type = 'Memcached'; //会话 privat ...
 - MySQL主从同步添加至zabbix监控
			
参考文档:https://blog.csdn.net/hellowidow_2020/article/details/78985368 https://www.cnblogs.com/cdjia ...