题目标签:String

 题目可以让在 偶数位置的 chars 互换, 也可以让 在 奇数位置的 chars 互换。

 所以为了 return 正确的 group 数量,需要把 那些重复的 给排除掉。

 可以把在 偶数位置的 chars 都拿出来 组成一个 string a, 同样的把 在奇数位置上的 chars 都拿出来组成一个 string b,分别把a 和 b 排序一下,再把两个a 和 b组合并且存入 HashSet。

 最后只要返回 HashSet 的 size 就可以了。

Java Solution:

Runtime beats 74.65%

完成日期:10/24/2018

关键点:把偶数位置 和 奇数位置的 chars 分别组成string,再排序,再组成新的String

 class Solution
{
public int numSpecialEquivGroups(String[] A)
{
Set<String> seen = new HashSet<>(); for(String str: A)
{
String evenStr = "";
String oddStr = ""; for(int i = 0; i < str.length(); i++)
{
if(i % 2 == 0) // even index
{
evenStr += str.charAt(i);
}
else // odd index
{
oddStr += str.charAt(i);
}
} seen.add(sortString(evenStr) + sortString(oddStr)); } return seen.size();
} private String sortString(String s)
{
char[] arr = s.toCharArray();
Arrays.sort(arr); return new String(arr);
}
}

参考资料:N/A

LeetCode 题目列表 - LeetCode Questions List

题目来源:https://leetcode.com/

LeetCode 893. Groups of Special-Equivalent Strings (特殊等价字符串组)的更多相关文章

  1. [Swift]LeetCode893. 特殊等价字符串组 | 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 ...

  2. [LeetCode] 583. Delete Operation for Two Strings 两个字符串的删除操作

    Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 t ...

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

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

  5. 【LeetCode】1128. Number of Equivalent Domino Pairs 等价多米诺骨牌对的数量(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典统计 代码 复杂度分析 日期 题目地址:http ...

  6. Codeforces 559B - Equivalent Strings

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

  7. [LeetCode] 712. Minimum ASCII Delete Sum for Two Strings 两个字符串的最小ASCII删除和

    Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal. ...

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

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

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

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

随机推荐

  1. Jmeter各组件介绍 及 使用

    本篇主要讲述Jmeter的各个组件及简单使用,其中包括以下内容: 一.线程组二.逻辑控制器三.配置元件四.定时器五.后置处理器六.断言七.监听器 八.参数化 网上大神整理的链接:http://blog ...

  2. Android开发笔记(3)——GridLayout

    笔记链接:http://www.cnblogs.com/igoslly/p/6799939.html GirdLayout 计算器实例及详尽的笔记:http://www.cnblogs.com/sky ...

  3. sql server truncate table 删除表数据限制条件

    truncate 注释 注释TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行.但 TRUNCATE TABLE 比 DELETE 速度快 ...

  4. 生产环境4.3.5jboss内存调优

    1.查看jboss的监控工具 http://XXX/jmx-console/htmladaptor 2.查看jvm的监控工具 jdk\bin jvisualvm.exe jmc.exe 3.查看jbo ...

  5. httponlycookie

    cookie cookie是目前标识用户身份一项非常流行的技术:设置httponly的cookie客户端是不能通过js来修改的:你以为这样就万事大吉,没有办法伪造了吗? 背景介绍 假设网站A通过设置h ...

  6. Zynq7000系列之芯片引脚功能综述

    很多人做了很久的FPGA,知道怎么去给信号分配引脚,却对这些引脚的功能及其资源限制知之甚少:在第一章里对Zynq7000系列的系统框架进行了分析和论述,对Zynq7000系列的基本资源和概念有了大致的 ...

  7. HDU_1548_A strange lift

    题意:一部电梯(共top层),每一楼有一个数字k,在该层只能上k层或者下k层(up和down按钮),问从当前层到目标层按按钮的最小次数. 分析:广度优先搜索. 总结:初写BFS,仿照别人的代码,这方面 ...

  8. swift Enumerations

    swift Enumerations enum.case.switch CaseIterable allCases 要区别枚举变量和关联值 枚举变量参与枚举运算: 关联值和rawvalue不参与. A ...

  9. 梦想Android版CAD控件2018.10.12更新

    下载地址: http://www.mxdraw.com/ndetail_10106.html 1. 增加读写对象扩展字典功能 2. 修改样条线显示错误 3. 修改shx文字显示错误 4. 增加向量运算 ...

  10. Linux(Centos7) 设置静态IP

    关于虚拟机 这里使用Centos7为例,因为linux是安装在在虚拟机中,这里先看一下虚拟机的网络适配器: 这里我使用的NAT模式,接着配置虚拟机的虚拟网络: 这里主要看一下VMnet8的设置: 这里 ...