题目介绍:

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

For example,

s = “anagram”, t = “nagaram”, return true.

s = “rat”, t = “car”, return false.

Note:

You may assume the string contains only lowercase alphabets.

Follow up:

What if the inputs contain unicode characters? How would you adapt your solution to such case? ##

思路分析:

题意是判断两个字符串包含的字符是不是相同,这样的问题,可以通过排序来简化 ,这个题目和前面的一个一片博客的题目(判断数组是否包含重复的元素)很相似,可以对照着

leetcode之旅(8)-Contains Duplicate

代码:

public class Solution {
    public boolean isAnagram(String s, String t) {
        char[] oneArray = s.toCharArray();
        char[] twoArray = t.toCharArray();
        Arrays.sort(oneArray);
        Arrays.sort(twoArray);
        int oneLength = oneArray.length;
        int  twoLength = twoArray.length;
        if(oneLength ==twoLength){
            for(int i = 0;i < oneLength;i++){
                if(oneArray[i] == twoArray[i]){

                }else{
                    return false;
                }
            }
        }else{
            return false;
        }
        return true;
    }
}

LeetCode之旅(13)-Valid Anagram的更多相关文章

  1. 【leetcode❤python】242. Valid Anagram

    class Solution(object):    def isAnagram(self, s, t):        if sorted(list(s.lower()))==sorted(list ...

  2. [LeetCode&Python] Problem 242. Valid Anagram

    Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...

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

  4. leetcdoe Valid Anagram

    题目连接 https://leetcode.com/problems/valid-anagram/ Valid Anagram Description Given two strings s and ...

  5. leetcode面试准备:Valid Anagram

    leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an ...

  6. LeetCode 242. 有效的字母异位词(Valid Anagram)

    242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...

  7. 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)

    22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...

  8. 【LeetCode】242. Valid Anagram (2 solutions)

    Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For ...

  9. [leetcode]242. Valid Anagram验证变位词

    Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...

随机推荐

  1. -eq、-ne、-gt、-ge、-lt、-le英文意思

    在shell脚本中,使用-eq.-ne.-gt.-ge.-lt.-le进行整数的比较.英文意思分别为: -eq :equal(相等) -ne :not equal(不等) -gt  :greater ...

  2. Dynamics CRM 安装Microsoft Dynamics CRM Reporting Extensions

    在装完CRM Server 后这个组件是必须安装的,但今天由于我的大意在客户安装生产环境时,告诉客户这个组件装在APP服务器上,导致客户安装时 SSRSInstance怎么都是空的,害的人家找了半天原 ...

  3. Android初级教程:对文件和字符串进行MD5加密工具类

    转载请注明出处:http://blog.csdn.net/qq_32059827/article/details/52200008   点击打开链接 之前写过一篇博文,是针对字符串进行md5加密的.今 ...

  4. Centos7安装JStorm2.1.1

    系统环境 Centos7 外网ip 182.254.145.66 内网ip 10.105.23.114 安装位置  /usr/local/jstorm-2.1.1 安装zookeeper 参见 htt ...

  5. tomcat请求路由映射核心组件Mapper

    Mapper组件的核心功能是提供请求路径的路由映射,根据某个请求路径通过计算得到相应的Servlet(Wrapper).这节看下Mapper的实现细节,包括Host容器.Context容器.Wrapp ...

  6. J2EE进阶(四)Spring配置文件详解

    J2EE进阶(四)Spring配置文件详解 前言 Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程 ...

  7. 【一天一道LeetCode】#155. Min Stack

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Design ...

  8. 《java入门第一季》之集合框架(Collection小儿子Set集合)

    /*  * Collection主要的连个儿子:  * |--List  * 有序(存储顺序和取出顺序一致),可重复  * |--Set  * 无序(存储顺序和取出顺序不一致),唯一  *   * H ...

  9. ROS_Kinetic_13 ROS数据录制与回放

    ROS_Kinetic_13 ROS数据录制与回放 官网教程:http://wiki.ros.org/cn/ROS/Tutorials/Recording%20and%20playing%20back ...

  10. Cocos2D:塔防游戏制作之旅(六)

    现在,创建一个新的类用来表示炮塔.添加新的类文件,名称为Tower,继承于CCNode. 替换Tower.h文件为如下内容: #import "cocos2d.h" #import ...