LeetCode之旅(13)-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.
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的更多相关文章
- 【leetcode❤python】242. Valid Anagram
class Solution(object): def isAnagram(self, s, t): if sorted(list(s.lower()))==sorted(list ...
- [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: ...
- 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 ...
- leetcdoe Valid Anagram
题目连接 https://leetcode.com/problems/valid-anagram/ Valid Anagram Description Given two strings s and ...
- leetcode面试准备:Valid Anagram
leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an ...
- LeetCode 242. 有效的字母异位词(Valid Anagram)
242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- 【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 ...
- [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: ...
随机推荐
- 财务模块多组织,GL, SLA, SOB, COA, BSV, CCID, LE 概念的简单介绍
GL= General Ledger 指的是Oracle 的总帐系统. application_id = 101. 在uk似乎居然还有不同的解释(In the UK, it was refer ...
- mxgraph进阶(三)Web绘图——mxGraph项目实战(精华篇)
Web绘图--mxGraph项目实战(精华篇) 声明 本文部分内容所属论文现已发表,请慎重对待. 需求 由于小论文实验需求,需要实现根据用户日志提取出行为序列,然后根据行为序列生成有向图的形式 ...
- Mybatis插入MySQL数据库中文乱码
Mybatis插入MySQL数据库中文乱码 在dataSource.properties配置文件中设置useUnicode=true&characterEncoding=utf-8编码即可. ...
- RTB--Real TimeBidding模式的互联网广告(实时竞价的广告投放)
RTB(real time bidding)实时竞价允许广告买家根据活动目标.目标人群以及费用门槛等因素对每一个广告及每次广告展示的费用进行竞价.竞价成功后获得广告展示机会,在展示位置上展示广告. 其 ...
- TCP三次握手及其背后的缺陷
概述 总结一下TCP中3次握手过程,以及其原生的缺陷 引起的SYN Flood的介绍 [1]TCP三次握手 [2]SYN Flood 1.TCP连接建立--三次握手 几个概念: [1]seq:序号,占 ...
- (NO.00003)iOS游戏简单的机器人投射游戏成形记(六)
为什么要将手臂移动的代码单独放在一个方法中? 其实这里是多次重构之后的版本.原来的移动代码是放在touchMoved方法里的.后来发现除了触摸手臂移动方式外,还要实现触摸屏幕移动手臂这第二种方式. 所 ...
- H5学习之旅-H5的基本标签(2)
H5的标签和html的标签没什么区别,主要介绍H5的基本标签 1.基础标签header和body,header的<title>元素主要是显示在标签页面里面,以及设置使用的语言和编码格式.b ...
- JAVA应用程序转换为Applet
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41673295 将一个图形的JAVA应用程序转换为能够嵌入在 ...
- VMware中安装系统提示没有可用的映像(No image available)
今天新建了个虚机在装系统的时候提示"没有可用的映像" 之所以会出现这种情况是因为在新建虚机的时候选择的设置不同导致的,此处不管选第一项还是第二项都会虚机设置中多了一个软盘的配置项, ...
- mysql进阶(二十三)数据库事务四大特性
数据库事务四大特性 原子性.一致性.分离性.持久性 原子性 事务的原子性指的是,事务中包含的程序作为数据库的逻辑工作单位,它所做的对数据修改操作要么全部执行,要么完全不执行.这种特性称为 ...