[抄题]:

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?

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

[一句话思路]:

字母就用26,字符用256

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

49. Group Anagrams 打碎

[代码风格] :

class Solution {
public boolean isAnagram(String s, String t) { //ini
int[] chars = new int[26]; //for loop, +s, -t
for (int i = 0; i < s.length(); i++) {
chars[s.charAt(i) - 'a']++;
}
for (int j = 0; j < t.length(); j++) {
chars[t.charAt(j) - 'a']--;
} //return i != 0
for (int i = 0; i < chars.length; i++) {
if (chars[i] != 0) return false;
} return true;
}
}

242. Valid Anagram 两个串的最基础版本的更多相关文章

  1. 242. Valid Anagram(C++)

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

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

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

  3. LN : leetcode 242 Valid Anagram

    lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...

  4. 【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 ...

  5. [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: ...

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

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

  7. LeetCode 242 Valid Anagram

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

  8. (easy)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 = &q ...

  9. 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 = & ...

随机推荐

  1. android Application Project目录结构

    src:存放java源文件 gen: 资源配置文件 Android4.0: 4.0 类库 Android Private Lib: 支持库 Android Dependencies: android ...

  2. nyoj-115-城市平乱(dijkstra算法)

     题目链接 /* Name:nyoj-115-城市平乱 Copyright: Author: Date: 2018/4/25 17:28:06 Description: dijkstra模板题 枚举从 ...

  3. ICE 的回调

    使用分布式计算中间件ICE到现在已经有一年多了,在这一年里里面对ICE的理解.应用比较熟悉. 使用ICE写分布式软件,确实是很方便:ICE比较稳定.可靠,调用返回速度低延迟,使用简单,学习曲线不是很陡 ...

  4. 让camera实现类似cs第一人称视角旋转和位移

    直接把这个脚本挂在摄像机上就可: using System.Collections; using System.Collections.Generic; using UnityEngine; /* * ...

  5. ubuntu tftp server config

    1.安装tftp-server sudo apt-get install tftpd-hpa sudo apt-get install tftp-hpa(如果不需要客户端可以不安装) tftp-hpa ...

  6. angular +H5 上传图片 与预览图片

    //index.html <form class="form-horizontal"> <div class="panel panel-default& ...

  7. POJ1733:Parity game

    浅谈并查集:https://www.cnblogs.com/AKMer/p/10360090.html 题目传送门:http://poj.org/problem?id=1733 带权并查集裸题.区间和 ...

  8. 异常:java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlType

    这个是jdK版本的问题的. 本地编译的jar包是1.8的,但是跑jar包的环境jdk版本是1.9的. 升级1.9之后由于jdk当方面的取消了几个jar,所以导致编译起不来. 明天研究一下如何添加jar ...

  9. System.Data.SQLite.dll控件常规安装方法

    原文地址:http://www.jb51.net/dll/System.Data.SQLite.dll.html 文件运行必须安装   Microsoft Visual C++ 2010 SP1 Re ...

  10. 【转】S1 Setup

    概念 S1是eNB和MME之间交换应用层配置数据的接口的名称.它是在建立TNL完成后的第一个S1AP的操作,S1的建立意味着eNB和MME之间之前已经存在的所有应用层数据将被全部清空,所有的数据将被重 ...