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.

思路:

将两个字符串转为char数组,排序后查看二者是否相等。

解法:

 1 import java.util.Arrays;
 2
 3 public class Solution
 4 {
 5     public boolean isAnagram(String s, String t)
 6     {
 7        char[] charS = s.toCharArray();
 8        char[] charT = t.toCharArray();
 9
10        Arrays.sort(charS);
11        Arrays.sort(charT);
12
13        if(Arrays.equals(charS, charT))
14           return true;
15        else
16           return false;
17     }
18 }

转载于:https://www.cnblogs.com/wood-python/p/5732336.html

LeetCode 242 Valid Anagram相关推荐

  1. [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 ...

  2. [leetcode]242. Valid Anagram判断两个字符串是不是包含相同字符的重排列

    /*思路是判断26个字符在两个字符串中出现的次数是不是都一样,如果一样就返回true.记住这个方法*/if (s.length()!=t.length())return false;int[] wor ...

  3. [LeetCode] NO. 242 Valid Anagram

    [题目] Given two strings s and t, write a function to determine if t is an anagram of s. For example, ...

  4. Leet Code OJ 242. Valid Anagram [Difficulty: Easy]

    题目: Given two strings s and t, write a function to determine if t is an anagram of s. For example, s ...

  5. 【To Do! 重点 正则表达式】LeetCode 65. Valid Number

    LeetCode 65. Valid Number 本博客转载自:[1]http://www.cnblogs.com/yuzhangcmu/p/4060348.html [2]https://blog ...

  6. 【回文串14】LeetCode 680. Valid Palindrome II

    LeetCode 680. Valid Palindrome II Solution1:我的答案 复杂度是O(n)O(n)O(n),不算好啊.. 注意:对于c++中string对象常用的insert( ...

  7. 【回文串3】LeetCode 125. Valid Palindrome

    LeetCode 125. Valid Palindrome Solution1:我的答案 复杂度为O(n)O(n)O(n),写法不是很简练啊. class Solution { public:boo ...

  8. LeetCode 36. Valid Sudoku

    LeetCode 36. Valid Sudoku Solution1:我的答案,比较笨.但是清晰易懂好上手啊~~~ class Solution { public:bool isValidSudok ...

  9. [勇者闯LeetCode] 125. Valid Palindrome

    [勇者闯LeetCode] 125. Valid Palindrome Description Given a string, determine if it is a palindrome, con ...

  10. LeetCode OJ:Valid Anagram(有效字谜问题)

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

最新文章

  1. 【jquery】jquery基础知识
  2. 刻意练习:LeetCode实战 -- Task27.分发饼干
  3. 项目经理的超越(一)你超越了吗?
  4. Nagios 安装配置
  5. WP 前台或后台显示ShellToast
  6. 集训2--进程控制理论
  7. 全能直播王pc版_企鹅游戏直播助手v2.28.330.8-企鹅游戏直播助手PC版下载
  8. Django的 select_related 和 prefetch_related 函数对 QuerySet 查询的优化(二)
  9. 字节流转换为对象的方法
  10. MQ学习(一)----JMS规范(转发整合)
  11. MySQL优化详解(五)——MySQL分库分表
  12. JSADS-日志对象MyLogger
  13. 计算机 word 节是什么,Word中的分节符是什么,如何使用?
  14. 记录一下学习EFCore中的基础知识
  15. LOJ#515. 「LibreOJ β Round #2」贪心只能过样例(bitset)
  16. plantuml介绍与使用
  17. 安卓直播详细教程(三)-----ijkplayer打造个性化控制界面
  18. cygwin下编译报错 `addrinfo hints‘ has incomplete type and cannot be defined
  19. 小米book pro16笔记本怎么U盘安装系统教学分享
  20. Matlab快速创建矩阵的方法(创建特殊矩阵)

热门文章

  1. Linq to sql 增删改查
  2. 【BERT】源码分析(PART I)
  3. 【每日算法Day 67】经典面试题:手动开根号,你知道几种方法?
  4. 每日算法系列【EOJ 3031】二进制倒置
  5. 吴恩达《神经网络与深度学习》课程笔记(1)-- 深度学习概述
  6. 2.5 分类模型评估指标—AUC与ROC及绘制混淆矩阵与ROC曲线
  7. 统计学习方法读书笔记12-逻辑斯蒂回归与最大熵
  8. 一条Select语句丛生到死的处理过程
  9. DDC——Deep Domain Confusion Maximizing for Domain Invariance
  10. 最优化知识笔记整理汇总