[抄题]:

You are given an array A of strings.

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

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.

Example 1:

Input: ["a","b","c","a","c","c"]
Output: 3
Explanation: 3 groups ["a","a"], ["b"], ["c","c","c"]

Example 2:

Input: ["aa","bb","ab","ba"]
Output: 4
Explanation: 4 groups ["aa"], ["bb"], ["ab"], ["ba"]

Example 3:

Input: ["abc","acb","bac","bca","cab","cba"]
Output: 3
Explanation: 3 groups ["abc","cba"], ["acb","bca"], ["bac","cab"]

Example 4:

Input: ["abcd","cdab","adcb","cbad"]
Output: 1
Explanation: 1 group ["abcd","cdab","adcb","cbad"]

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[一句话思路]:

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

多开几个数组就行了

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[算法思想:迭代/递归/分治/贪心]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

[是否头一次写此类driver funcion的代码] :

[潜台词] :

class Solution {
public int numSpecialEquivGroups(String[] A) {
//corner case
if (A == null || A.length == 0) return 0; //initialization: 2 arrays and a set
Set<String> set = new HashSet<>();
for (String s : A) {
int[] old = new int[26];
int[] even = new int[26];
for (int i = 0; i < s.length(); i++) {
//add to the old or even array
if (i % 2 == 0) {
even[s.charAt(i) - 'a']++;
} else {
old[s.charAt(i) - 'a']++;
}
}
String sig = Arrays.toString(old) + Arrays.toString(even);
set.add(sig);
}
/*
acb
old [0, 0, 1...]
even [1, 1, 0...] bca
old[0, 0, 1...]
even[1, 1, 0...]
*/ //return
return set.size();
}
}

893. Groups of Special-Equivalent Strings 奇数偶数位上的相同数的更多相关文章

  1. [Solution] 893. Groups of Special-Equivalent Strings

    Difficulty: Easy Problem You are given an array A of strings. Two strings S and T are special-equiva ...

  2. day4 对偶数、偶数位的操作

    1.函数fun()的功能:从低位开始取出整形变量s中偶数位上的数,依次构成一个新数放在t中.高位仍在高位. 效果理想:但是经测试的时候出现了错误 输入987654321时,打印出来的却是18681.经 ...

  3. 【leetcode】893. Groups of Special-Equivalent Strings

    Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...

  4. [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 ...

  5. 893. Groups of Special-Equivalent Strings - LeetCode

    Question 893. Groups of Special-Equivalent Strings Solution 题目大意: AB两个字符串相等的条件是:A中偶数位出现的字符与B中偶数位出现的字 ...

  6. 【Leetcode_easy】893. Groups of Special-Equivalent Strings

    problem 893. Groups of Special-Equivalent Strings 题意: 感觉参考代码也是有点问题的... 参考 1. Leetcode_easy_893. Grou ...

  7. Equivalent Strings

    Equivalent Strings 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/E 题意: 给出 ...

  8. Codeforces Round #313 (Div. 1) B. Equivalent Strings

    Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...

  9. Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力

    B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559 ...

随机推荐

  1. leetcode 题解: Gray Code

    第一眼看到就是枚举,回溯法. n位的ans就是在n-1的ans的基础上,每一个在首位加上1. 但是有个难点,要保证相邻两数之间只有一位在变化,怎么办? 首先 00 00 01 00 01 11 10 ...

  2. iframe+form上传文件

    <iframe id="iframe1" name="ifra1" style="display: none"></ifr ...

  3. ORM对单表的增删改查

    表记录的增加: 1)b = Book(name='python', price=99) b.save() 2)Book.objects.create(name='python', price=99) ...

  4. Xcode 8 注释快捷键失效

    sudo /usr/libexec/xpccachectl 重启

  5. zookeeper windows7下集群搭建

    模拟分布式环境!!!  搞了好几天,各种错误!!终于成功了. 环境: windows7 /centos/xsheel    安装了三个虚拟机... 1.下载zookeeper http://archi ...

  6. Tomcat虚拟目录设置

    ssh $host "rm -fr /var/www/$tomcat_name/webapps/*" 远程分发war包部署tomcat项目时,需要先清除项目目录. -------- ...

  7. Zabbix3.0版报警设置

    各项报警历史记录查看:“报表--Action log” ------------------------------------------------------------------------ ...

  8. C# 指定平台编译项目

    如CefSharp就需要指定平台,项目为Any CPU时,无法编译,总会提示出错. 如: CefSharp.Common contains unmanaged resoures, set your p ...

  9. EF 安装框架

    在NuGet中安装ef框架 命令:Install-package EntityFramework

  10. mab算法

    https://zhuanlan.zhihu.com/p/21388070?refer=resyschina 专治选择困难症——bandit算法 改善:https://zhuanlan.zhihu.c ...