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 ...
随机推荐
- linux环境下搭建solr服务器--单机版
前提需要在安装好jdk和tomcat,本人用的是jdk1.8+tomcat8.5+solr4.10. 第一步:安装linux.jdk.tomcat.(这步都是比较简单的,就不多说了) 第二步:把sol ...
- 1. 了解Git和Github
1. 了解Git和Github 1.1 什么是Git Git是一个免费.开源的版本控制软件 1.2 什么是版本控制系统 版本控制是一种记录一个或若干个文件内容变化,以便将来查阅特定版本修订情况得系统. ...
- 在一个元素上:hover,改变另一个元素的css属性
如果二者是父子关系,可以写成这种: .face:hover .eye-bottom { margin-top: 30px; } 如果是兄弟关系: .face:hover+.ear-wrap { tra ...
- canvas 实现 github404动态效果
使用canvas来完成github404的动态效果 前几天使用css样式和js致敬了一下github404的类似界面,同时最近又接触了canvas,本着瞎折腾的想法,便借着之前的js的算法,使用can ...
- python-输入列表,求列表元素和(eval输入应用)
在一行中输入列表,输出列表元素的和. 输入格式: 一行中输入列表. 输出格式: 在一行中输出列表元素的和. 输入样例: [3,8,-5] 输出样例: 6 代码: a = eval(input()) t ...
- PAT A1035 Password
题目描述: To prepare for PAT, the judge sometimes has to generate random passwords for the users. The pr ...
- window.location.href用法与a标签的比较
1.在使用这两种方法进行页面的跳转时,这两种方法都能够有效的实现该功能 但是其原理不尽相同 第一:window.location.href()方法必须书写在js中 <html> <h ...
- 基于nodejs中实现跨域的方法
一般情况下跨域是通过ajax的方式请求数据,通过js在不同的域之间进行数据传输或者通信: 只有通过ajax方式获取请求的时候才会有跨域问题需要解决: 例如在本地模拟两个服务端. 一个服务端去通过aja ...
- python---实现单例模式
""" 单例模式 单利模式是一种设计模式, 应用该模式的类只会生成一个实例, 可以保证在程序的不同位置 都可以且仅可以取到同一个对象实例. 如果实例不存在, 会创建一个实 ...
- spring配置数据源(交给spring容器完成)
##将DataSource的创建权交给spring容器去完成 1.导入spring依赖 <dependency> <groupId>org.springframework< ...