这道题主义的就是,要利用数组自带的sort函数。

此外,注意,利用hash来判断是否出现了。

  public static  ArrayList<String> sortStrings(String[] str, int n) {
// write code here
ArrayList<String> res = new ArrayList();
//sort
Arrays.sort(str);
HashSet<String> hash = new HashSet();
for(int i = 0; i <n; i++){
char[] c = str[i].toCharArray(); Arrays.sort(c); String tmp = new String(c);
if(!hash.contains(tmp)){ hash.add(tmp);
res.add(str[i]);
} } return res;
}

11.2---字符串数组排序,删除变位词(CC150)的更多相关文章

  1. 005推断两个字符串是否是变位词 (keep it up)

    写一个函数推断两个字符串是否是变位词. 变位词(anagrams)指的是组成两个单词的字符同样,但位置不同的单词.比方说, abbcd和abcdb就是一对变位词 这也是简单的题. 我们能够排序然后对照 ...

  2. [Swust 549]--变位词(vector水过)

    Time limit(ms): 1000 Memory limit(kb): 65535   Description 输入N和一个要查找的字符串,以下有N个字符串,我们需要找出其中的所有待查找字符串的 ...

  3. [CareerCup] 11.2 Sort Anagrams Array 异位词数组排序

    11.2 Write a method to sort an array of strings so that all the anagrams are next to each other. 这道题 ...

  4. lintcode-158-两个字符串是变位词

    158-两个字符串是变位词 写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 说明 What is Anagram? Two strings are ...

  5. LeetCode 438. Find All Anagrams in a String (在字符串中找到所有的变位词)

    Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...

  6. 36.在字符串中删除特定的字符[Delete source from dest]

    [题目] 输入两个字符串,从第一字符串中删除第二个字符串中所有的字符.例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”. ...

  7. Leetcode 242. Valid Anagram(有效的变位词)

    Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...

  8. 变位词(0029)-swustoj

    变位词(0029)水题 变位词如果两个单词的组成字母完全相同,只是字母的排列顺序不一样,则它们就是变位词,两个单词相同也被认为是变位词.如tea 与eat , nic 与cin, ddc与dcd, a ...

  9. 南大算法设计与分析课程OJ答案代码(4)--变位词、三数之和

    问题 A: 变位词 时间限制: 2 Sec  内存限制: 10 MB提交: 322  解决: 59提交 状态 算法问答 题目描述 请大家在做oj题之前,仔细阅读关于抄袭的说明http://www.bi ...

随机推荐

  1. (转)Java API设计清单

    转自: 伯乐在线 Java API设计清单 英文原文 TheAmiableAPI 在设计Java API的时候总是有很多不同的规范和考量.与任何复杂的事物一样,这项工作往往就是在考验我们思考的缜密程度 ...

  2. (转)Java字符串

    转自:http://blog.sina.com.cn/s/blog_899678b90101brz0.html 创建字符串有两种方式:两种内存区域(字符串池,堆)1," " 引号创 ...

  3. nuget包管理器控制台下的powershell脚本介绍

    http://personball.com/powershell/2016/07/15/powershell-tips 定制自己的powershell,减少重复工作 安装一系列自己的常用nuget包 ...

  4. Orchard源码分析(4):Orchard.Environment.OrchardStarter类

    概述 OrchardStarter类是个静态类,主要作用是配置Autofac容器以及创建IOrchardHost(DefaultOrchardHost)对象,分别对应CreateHost和Create ...

  5. JDBC连接池

    650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/45/0C/wKiom1PjixLxfknCAAEbp-e9Bq ...

  6. 网页JQ基础之jq-隐藏以及显示特效

    简单的 隐藏以及显示的 JQ 的代码如下: <!DOCTYPE html> <html> <head> <script src="/jquery/j ...

  7. 请问如何查看mysql 的端口号?

    mysql> show variables like 'port'; +---------------+-------+ | Variable_name | Value | +--------- ...

  8. PHP无限极分类生成树方法,无限分级

    你还在用浪费时间又浪费内存的递归遍历无限极分类吗,看了该篇文章,我觉得你应该换换了.这是我在OSChina上看到的一段非常精简的PHP无限极分类生成树方法,巧在引用,整理分享了. function g ...

  9. Node.SelectNodes

    http://www.crifan.com/csharp_under_some_node_search_specific_child_node/ https://msdn.microsoft.com/ ...

  10. 从Google开源RE2库学习到的C++测试方案

    最近因为科研需求,一直在研究Google的开源RE2库(正则表达式识别库),库源码体积庞大,用C++写的,对于我这个以前专供Java的人来说真的是一件很痛苦的事,每天只能啃一点点.今天研究了下里面用到 ...