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. Codeforces Round #313 (Div. 1)

    官方英文题解:http://codeforces.com/blog/entry/19237 Problem A: 题目大意: 给出内角和均为120°的六边形的六条边长(均为正整数),求最多能划分成多少 ...

  2. (BFS)poj3669-Meteor Shower

    题目地址 为判断某时刻能否走到某位置,建立shi数组,记录某位置最早t时刻就不能走.(初始化为-1)之后开始从(0,0)出发bfs,用bu数组记录走到某一位置时花费的步数,并且需要用vi数组记录是否走 ...

  3. centos6环境下安装tmux

    Install tmux on CentOS 6:1. sudo rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-releas ...

  4. python导入cx_Oracle报错的问题!

    import cx_Oracle 总是报错:ImportError: DLL load failed: 找不到指定的模块. 或者:ImportError: DLL load failed: %1 不是 ...

  5. VisualSVN5.0.1补丁原创发布

    VisualSVN5.0.1补丁原创发布

  6. as3 代码加解密

    private var loader:URLLoader; ... private function init():void { loader = new URLLoader; req=URLRequ ...

  7. AngularJs的UI组件ui-Bootstrap分享(十四)——Carousel

    Carousel指令是用于图片轮播的控件,引入ngTouch模块后可以在移动端使用滑动的方式使用轮播控件. <!DOCTYPE html> <html ng-app="ui ...

  8. UIView点击事件。弹出视图,背景虚化。

    @interface CountryViewController //背景 @property (strong, nonatomic) UIView *BackView; end //设置背景虚化 - ...

  9. 算法-QuickSort

    #include <stdlib.h> #include <iostream> #include <vector> using namespace std; tem ...

  10. C# 里的if/switch

    今天又重新翻了翻C# Step by Step if 语句 if(bool 表达式) { 语句块: } else { 语句块: } switch(day) { case 0: dayName=&quo ...