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的更多相关文章

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

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

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

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

  3. Equivalent Strings

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

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

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

  5. Codeforces Round #313 (Div. 2) D. Equivalent Strings

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

  6. 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 ...

  7. Equivalent Strings (字符串相等?)

    Equivalent Strings   E - 暴力求解.DFS Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I ...

  8. Codeforces 559B - Equivalent Strings

    559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...

  9. Codeforces Round #313 D. Equivalent Strings(DFS)

    D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. 机器学习 machine learn

    机器学习 机器学习 概述 什么是机器学习 机器学习是一门能够让编程计算机从数据中学习的计算机科学.一个计算机程序在完成任务T之后,获得经验E,其表现效果为P,如果任务T的性能表现,也就是用以衡量的P, ...

  2. 单总线协议DS1820

    一. DS18B20简介 DS18B20数字温度传感器接线方便,封装后可应用于多种场合,如管道式,螺纹式,磁铁吸附式,不锈钢封装式.主要根据应用场合的不同而改变其外观.封装后的DS18B20可用于电缆 ...

  3. 一个模型预测控制(MPC)的简单实现

    1 生活中的启示 情景如下:你们团队每天早晨开一次例会,主要会议内容是你汇报工作进度,领导根据工作目标和工作进度,制定当天的工作计划,你领到工作计划后开始工作.每天都这样周而复始,从领导的角度看,这件 ...

  4. 淘宝 rem 机制入门学习

    一 移动设备尺寸多种多样,带来适配难度,有时甚至无从下手.1 移动设备上的Px 像素不等于设备的物理像素.iphone 6 作为开发标准设备不等于设备的物理像素.iPhone 5 物理宽度320iPh ...

  5. 基于React的仿QQ音乐(移动端)

    前言 由于这段时间工作上也是挺忙的,就没有时间去写这个项目,中间一直都是写写停停,进度也是非常慢的.正好前几天都还比较空,就赶紧抓着空闲时间去写这个项目,最后紧赶慢赶地完成了.本项目采用了React的 ...

  6. JavaScript中数组的方法和字符串方法总结

    数组是首先的一个对象, 可以通过Array构造器创建一个数组,数组方法总结如下 cacat()  链接两个数组 join()  将数组链接成字符串 pop() 删除最后一个元素  shift()  删 ...

  7. ubuntu修复找不到sudo命令

    1.首先,您需要安装该sudo命令.你可以使用 apt 包管理器来做到这一点.您需要以有权安装软件包的用户身份运行此命令,例如root: apt-get install sudo 2.下一步是为您自己 ...

  8. mpvue下拉刷新

    1 开启下拉刷新 在想要下拉刷新的页面的 main.json 里,添加: { "navigationBarTitleText": "页面标题", "e ...

  9. Spring Boot-@Configuration注解

    @Configuration:指明当前类是一个配置类,就是来替代spring的配置文件 @Configuration public class MyConfigFile { @Bean public ...

  10. 两个线程交替运行——使用synchronized+wait+notify实现

    public class ExecuteThread { private static Object obj = new Object(); private static boolean flag; ...