487. Name Deduplication

Given a list of names, remove the duplicate names. Two name will be treated as the same name if they are equal ignore the case.

Return a list of names without duplication, all names should be in lowercase, and keep the order in the original list.

Example

Example 1:

Input:["James", "james", "Bill Gates", "bill Gates", "Hello World", "HELLO WORLD", "Helloworld"]

Output:["james", "bill gates", "hello world", "helloworld"]

Clarification

You can assume that the name contains only uppercase and lowercase letters and spaces.

思路:

用hashmap去除重复,先把字符串转小写,调用toLowerCase方法,返回值要重新赋值给str!!

代码:

 public class Solution {
/**
* @param names: a string array
* @return: a string array
*/
public List<String> nameDeduplication(String[] names) {
List<String> result = new ArrayList<String>();
Map<String, Integer> map = new HashMap<String, Integer>();
for (String str : names) {
str = str.toLowerCase();
if (!map.containsKey(str)) {
map.put(str, 1);
result.add(str);
}
}
return result;
}
}

Lintcode487-Name Deduplication-Easy的更多相关文章

  1. 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优

    libsvm中有进行参数调优的工具grid.py和easy.py可以使用,这些工具可以帮助我们选择更好的参数,减少自己参数选优带来的烦扰. 所需工具:libsvm.gnuplot 本机环境:Windo ...

  2. Struts2 easy UI插件

    一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...

  3. Easy UI常用插件使用

    一.easy UI是类似于jQuery UI的插件库,它提供了丰富的各种常用插件:tree.datagrid... tree插件: 语法:$(selector).tree([settings]); 常 ...

  4. UVA-11991 Easy Problem from Rujia Liu?

    Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...

  5. CodeForces462 A. Appleman and Easy Task

    A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...

  6. easy ui插件

    简介: easy UI是类似于jQuery UI的插件库 注意:多脚本同时使用时,注意脚本冲突问题. 常用插件: 1.tree插件(tree插件实现动态树形菜单) 2.datagrid插件(datag ...

  7. 用TPP开启TDD的easy模式

    Test-Drived Development 测试驱动开发三步曲:写一个失败的测试用例->编写生产代码通过这个测试用例(transformation)->重构(refactor).重构是 ...

  8. Easy Sysprep更新日志-skyfree大神

    Easy Sysprep更新日志: Skyfree 发表于 2016-1-22 13:55:55 https://www.itsk.com/forum.php?mod=viewthread&t ...

  9. [官方软件] Easy Sysprep v4.3.29.602 【系统封装部署利器】(2016.01.22)--skyfree大神

    [官方软件] Easy Sysprep v4.3.29.602 [系统封装部署利器](2016.01.22) Skyfree 发表于 2016-1-22 13:55:55 https://www.it ...

  10. [原创] Easy SysLite V1.2 (2016.5.29更新,新增加WIN10支持,一个程序适配所有系统减肥)

    [原创] Easy SysLite V1.2 (2016.5.29更新,新增加WIN10支持,一个程序适配所有系统减肥) nohacks 发表于 2016-5-29 17:12:51 https:// ...

随机推荐

  1. 【托业】【跨栏】TEST05

    22 23 21. 22 23 24 25 REVIEW TEST05

  2. linux alias 命令 查看系统设置的命令别名

    alias命令用于查看或设置命令别名,但仅作用于该次登陆的会话,若要永久使用别名,可在 ~/.bashrc 中设定别名 [root@MongoDB ~]# alias // 查看别名 [root@Mo ...

  3. mybatis 分页插件

    博客地址http://www.jianshu.com/nb/5226994 引言 对于使用Mybatis时,最头痛的就是写分页,需要先写一个查询count的select语句,然后再写一个真正分页查询的 ...

  4. Mysql事务隔离级别学习

    这篇文章主要谈谈Mysql事务隔离级别的区别,以及自己的一些感受. 自己一直以来没搞懂“可重复读”和可提交读“两者之间的区别,通过此次的实践,清楚了两者之间的区别.废话不说,先上图看看这几个事务隔离级 ...

  5. Cocos Creator 获取当前URL取参数

    利用Javascript获取当前页的URL,这个问题起来好像很复杂,如果第一次去想这个问题,很多人估计又在琢磨到底又是哪个神一般的Javascript函数. 其实不是,Javascript获取当前页的 ...

  6. java 对象的一点小问题

    List<A> list = new ArrayList(); A a = new A(); for(int i=0;i<3;i++) { a.setI(i); list.add(A ...

  7. FB面经Prepare: Email User

    有一些账号,账号里面有一个或多个email, 如果两个账号有共同的email,则认为这两个账号是同一个人,找出哪些账号是同一个人 输入是这样的:数字是用户,字母是邮箱,有很多人有多个邮箱,找出相同的用 ...

  8. linux-git

  9. C# Unity的使用

    Unity是微软推出的IOC框架, 使用这个框架,可以实现AOP面向切面编程,便于代码的后期维护,此外,这套框架还自带单例模式,可以提高程序的运行效率. 下面是我自己的案例,以供日后参考: 使用VS2 ...

  10. servlet中如何实现通过Spring实现对象的注入

    @WebServlet("/BaseServlet")public class BaseServlet extends HttpServlet { private static f ...