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 = "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相关推荐
- [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 ...
- [leetcode]242. Valid Anagram判断两个字符串是不是包含相同字符的重排列
/*思路是判断26个字符在两个字符串中出现的次数是不是都一样,如果一样就返回true.记住这个方法*/if (s.length()!=t.length())return false;int[] wor ...
- [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, ...
- 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 ...
- 【To Do! 重点 正则表达式】LeetCode 65. Valid Number
LeetCode 65. Valid Number 本博客转载自:[1]http://www.cnblogs.com/yuzhangcmu/p/4060348.html [2]https://blog ...
- 【回文串14】LeetCode 680. Valid Palindrome II
LeetCode 680. Valid Palindrome II Solution1:我的答案 复杂度是O(n)O(n)O(n),不算好啊.. 注意:对于c++中string对象常用的insert( ...
- 【回文串3】LeetCode 125. Valid Palindrome
LeetCode 125. Valid Palindrome Solution1:我的答案 复杂度为O(n)O(n)O(n),写法不是很简练啊. class Solution { public:boo ...
- LeetCode 36. Valid Sudoku
LeetCode 36. Valid Sudoku Solution1:我的答案,比较笨.但是清晰易懂好上手啊~~~ class Solution { public:bool isValidSudok ...
- [勇者闯LeetCode] 125. Valid Palindrome
[勇者闯LeetCode] 125. Valid Palindrome Description Given a string, determine if it is a palindrome, con ...
- 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 = & ...
最新文章
- 【jquery】jquery基础知识
- 刻意练习:LeetCode实战 -- Task27.分发饼干
- 项目经理的超越(一)你超越了吗?
- Nagios 安装配置
- WP 前台或后台显示ShellToast
- 集训2--进程控制理论
- 全能直播王pc版_企鹅游戏直播助手v2.28.330.8-企鹅游戏直播助手PC版下载
- Django的 select_related 和 prefetch_related 函数对 QuerySet 查询的优化(二)
- 字节流转换为对象的方法
- MQ学习(一)----JMS规范(转发整合)
- MySQL优化详解(五)——MySQL分库分表
- JSADS-日志对象MyLogger
- 计算机 word 节是什么,Word中的分节符是什么,如何使用?
- 记录一下学习EFCore中的基础知识
- LOJ#515. 「LibreOJ β Round #2」贪心只能过样例(bitset)
- plantuml介绍与使用
- 安卓直播详细教程(三)-----ijkplayer打造个性化控制界面
- cygwin下编译报错 `addrinfo hints‘ has incomplete type and cannot be defined
- 小米book pro16笔记本怎么U盘安装系统教学分享
- Matlab快速创建矩阵的方法(创建特殊矩阵)