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


Solution
题目大意:
AB两个字符串相等的条件是:A中偶数位出现的字符与B中偶数位出现的字符相同且奇数位出现的字符也相同
按上述判定相等字符串的规则求去重后字符串的个数
思路:
strHash函数,传一个字符串,返回该字符串的奇数位字符和偶数位字符出现的在字母表中的分布
构造一个set来存储每个字符串的strHash后的结果
Java实现:
public int numSpecialEquivGroups(String[] A) {
Set<String> strSet = new HashSet<>();
for (String tmp : A) {
strSet.add(strHash(tmp));
}
return strSet.size();
}
private String strHash(String tmp) {
if (tmp.length() == 1) return tmp;
int[] cArr = new int[52];
int odd = 0;
for (char c : tmp.toCharArray()) {
cArr[(odd++ % 2 == 0 ? 26 : 0) + c - 'a']++;
}
StringBuilder sb = new StringBuilder();
for (int i : cArr) {
sb.append(i);
}
return sb.toString();
}
893. Groups of Special-Equivalent Strings - LeetCode的更多相关文章
- 【leetcode】893. Groups of Special-Equivalent Strings
Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...
- 【Leetcode_easy】893. Groups of Special-Equivalent Strings
problem 893. Groups of Special-Equivalent Strings 题意: 感觉参考代码也是有点问题的... 参考 1. Leetcode_easy_893. Grou ...
- Equivalent Strings
Equivalent Strings 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/E 题意: 给出 ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings
Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...
- Codeforces Round #313 (Div. 2) D. Equivalent Strings
D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...
- 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 ...
- Equivalent Strings (字符串相等?)
Equivalent Strings E - 暴力求解.DFS Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I ...
- Codeforces 559B - Equivalent Strings
559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...
- Codeforces Round #313 D. Equivalent Strings(DFS)
D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- leedcode_13 罗马数字转整数
罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值I 1V 5X 10L 50C 100D 500M 1000例如, 罗马数字 2 写做 II ,即为两个并列的 1 .12 ...
- 12_非线性理论基础_Lyapunov直接方法
- .NET面试题整理
.NET..NET Framework..NET Core和C#的解释各是什么? ASP.NET MVC和ASP.NET Web API的区别是什么? C#中的委托是什么?事件是不是一种委托? 简述P ...
- 前端工作面试HTML相关问题
前端工作面试HTML相关问题 Q: doctype(文档类型)的作用是什么? A: 在HTML中 doctype 有两个主要目的. 对文档进行有效性验证: 它告诉用户代理和校验器这个文档是按照什么DT ...
- ffmpeg将视频生成gif
1.安装ffmpeg 2.cmd中输入 ffmpeg -i 0.mp4 -f gif 0.gif 即可将视频转为gif
- window.location.href用法与a标签的比较
1.在使用这两种方法进行页面的跳转时,这两种方法都能够有效的实现该功能 但是其原理不尽相同 第一:window.location.href()方法必须书写在js中 <html> <h ...
- 微信小程序加密解密参数
加密:encodeURIComponent(参数) 解密:decodeURIComponent(参数)
- 利用css3渐变效果实现圆环旋转效果
* { margin: 0; padding: 0; } .stage { width: 200px; height: 130px; margin: 100px auto; position: rel ...
- 在ios里面返回上一级报错问题
$("#backPrev").attr("href","javascript:void(0);").click(function(){ ...
- 使用Vue_CLI_3快速创建项目