1. 把string变为char数组

2. 排序Arrays.sort()

public class Solution {
/**
* @param s: The first string
* @param b: The second string
* @return true or false
*/
public boolean anagram(String s, String t) {
if(s == null || t == null) return false;
if(s.length() != t.length()) return false; char[] arrs = s.toCharArray();
char[] arrt = t.toCharArray();
Arrays.sort(arrs);
Arrays.sort(arrt); boolean flag = true;
for(int i = 0; i < arrs.length; i++){
if(arrs[i] != arrt[i]){
flag = false; }
}
return flag;// write your code here
}
};

LintCode Two Strings Are Anagrams的更多相关文章

  1. Two Strings Are Anagrams

    Write a method anagram(s,t) to decide if two strings are anagrams or not. 判断两个字符串里的字符是否相同,也就是是否能够通过改 ...

  2. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  3. [LeetCode] Anagrams 错位词

    Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...

  4. Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  5. LeetCode-Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  6. 【Leetcode】【Medium】Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  7. [LeetCode]题解(python):049-Groups Anagrams

    题目来源 https://leetcode.com/problems/anagrams/ Given an array of strings, group anagrams together. For ...

  8. 49. Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  9. LeetCode49 Group Anagrams

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

随机推荐

  1. jquery tab 插件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. 基于H5的移动端开发,window.location.href在IOS系统无法触发问题

    最近负责公司的微信公众号开发项目,基于H5进行开发,某些页面window.location.href在Android机上能正常运行而IOS系统上无法运行,导致无法重定向到指定页面,查了好久终于找到方法 ...

  3. selenium+python环境搭建

    1.安装python-2.7.3.msi 2.安装pywin32-216.win32-py2.7.exe 3.下selenium包,selenium-2.35.0.tar.gz,放到D:\autote ...

  4. ionic的start-y属性初始化页面

    混合式开发移动app,要实现的是初始化页面时不展示搜索框,让页面向上移动一定位移. <ion-content class="has-subheader" start-y=&q ...

  5. Android深度探索--HAL与驱动开发----第二章读书笔记

    1. 底层开发工具包括: JDk6或者以上版本:Eclipse3.4或以上版本:ADT(用于开发Android应用程序),CDT(用于开发AndroidNDK程序):Android SDK:Andro ...

  6. VS2010编译Boost 1.57 静态链接库

    http://www.cnblogs.com/cuish/p/4175491.html 0.前提 Boost库版本 1.57.0 下载地址 http://www.boost.org/users/his ...

  7. hession

    Hessian是一个轻量级的remoting onhttp工具,使用简单的方法提供了RMI的功能. 相比WebService,Hessian更简单.快捷.采用的是二进制RPC协议,因为采用的是二进制协 ...

  8. Java的多态

    多态的定义: 同一种行为,在不同对象上有不同的表现形式 实现多态的条件: 要有继承 要有方法的重写 要有父类的引用指向子类的对象 代码如下: public class Animal { String ...

  9. 初学SQL常用到的一些指令

    一.库 查看有哪些库:show databases; 进入某个库:use 库名; 新增库:create database atm; (atm为库名) 删除库:drop database if exis ...

  10. 继续向peersim的event-driven模式开火!(新手勿喷)

    昨天学习了peersim的cycle模式,今天开始继续悟事件模式. 总的来说,我个人认为事件模式是周期模式的升级版,或者说,周期模式只是事件模式的一个子功能. 事件模式是基于时间和事件的(没打错),每 ...