[抄题]:

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. jquery 设计的思路-----初级

    jquery.js 很经典,其中有一些设计思路简直非常经典 1.安全的创建一个构造函数并进行调用: <script> // 这是一种安全的构造函数的创建方法,在调用构造函数G的时候,不论使 ...

  2. 2.Geany安装后编译器配置

    生成 --> 设置生成命令 -->  Compile & Execute : C:\Users\29742\AppData\Local\Programs\Python\Python ...

  3. redis集群报错:(error) MOVED 11469 192.168.163.249:7002

    应该是你没有启动集群模式(即缺少了那个"-c"): redis-cli -c -h yourhost -p yourpost

  4. [ SHELL编程 ] 远程服务器传输文件

    在shell编程中经常需要获取远程服务器文件.手工操作中使用scp命令完成.为避免脚本执行scp输入密码进行交互,需先建立本机服务器当前用户和远程服务器指定用户的信任关系.具体代码见操作实例,重点关注 ...

  5. centos6.9出现openvpn:error=certificate signature failure的处理

    原因: 将原来openwrt上用的证书复制到centos 6.9后,客户端都连不上了,查了服务器log,出现是error=certificate signature failure错误. 处理方法见帖 ...

  6. ajax分页代码

    <meta charset="utf-8"><?php//连接数据库$link = mysqli_connect('127.0.0.1','root','root ...

  7. JSP页面中的小知识

    1.<%…%>和<%!…%>的区别? <%…%>用于在JSP页面中嵌入Java脚本,即代码块 <%!…%>用于在JSP页面中申明变量或方法,可以在该页面 ...

  8. jQuery中的end()方法

    定义和用法 end() 方法结束当前链条中的最近的筛选操作,并将匹配元素集还原为之前的状态. 以上是官方说法,比较难理解. 还是用一个例子来说明 <!DOCTYPE html> <h ...

  9. (转)C#如何加载程序运行目录外的程序集

    https://www.cnblogs.com/guanglin/p/3200989.html 我们的应用程序部署的时候,目录结构一般不会只有运行程序的目录这一个,我们可能在运行目录下建子目录,也可能 ...

  10. php预定义字符

    Php中预定义字符的处理: 1,htmlspecialchars()把一些预定义的字符转换为 HTML 实体. 函数原型:htmlspecialchars(string,quotestyle,char ...