题目介绍:

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. UNIX网络编程——进程间通信概述

    一.顺序程序与并发程序特征 顺序程序特征 顺序性封闭性:(运行环境的封闭性)确定性可再现性 并发程序特征 共享性并发性随机性 二.进程互斥 1.由于各进程要求共享资源,而且有些资源需要互斥使用,因此各 ...

  2. (NO.00005)iOS实现炸弹人游戏(五):游戏数据的初始化(二)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 我们现在来依次看一下上篇中提到的各个方法,首先介绍的是updat ...

  3. 套接字工厂——ServerSocketFactory

    接收器Acceptor在接收连接的过程中,根据不同的使用场合可能需要不同的安全级别,例如在支付相关的交易就必须对信息加密后再发送,这其中还涉及到密钥协商的过程,而在另外一些普通场合则无需对报文加密.反 ...

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

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

  5. Java-IO之CharArrayReader

    CharArrayReader是字符数组输入流,CharArrayReader用于读取字符数组,继承于Reader操作的数据是以字符为单位. (1)CharArrayReader实际上是通过字符数组去 ...

  6. 02-Git简单使用

    Git安装(windows) https://code.google.com/p/msysgit/downloads/list 我们使用版本Git-1.7.9版本 百度网盘下载:链接:http://p ...

  7. 学习笔记-JS公开课三

    DOM技术概述 DOM : DocumentObject Model 将HTML标记型文档,封装成对象,提供更多的属性和行为 DOM的三级模型 第一级:将标记型文档,封装成对象,提供更多的属性和行为 ...

  8. 【VSTS 日志 15/11/18】 – 插件应用市场,RM,包管理器等

    [小编]从今天开始,我将在这个博客上连载Visual Studio Team Service的定期更新.VSTS是Team Foundation Server 的在线版本,微软每3周会对这个服务进行更 ...

  9. IDEA中运行KafkaWordCount程序

    1,从spark的example中找到KafkaWordCount.scala文件复制到idea编辑器中,引入包: 2,编辑configuration,     (1)KafkaWordCountPr ...

  10. outlook邮箱邮件与企业邮箱同步(outlook本地文件夹邮件,web邮箱里没有)

    用惯了outlook2010, 问题:今天将邮件放到自定义文件夹后,发现在web邮箱中看不到邮件了.不能同步到企业邮箱. 解决忙了一天,才知道是账户类型问题,pop3类型,只下载不上传.所以outlo ...