[抄题]:

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. Phone numbers

    Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, ...

  2. LeetCode 4 Keys Keyboard

    原题链接在这里:https://leetcode.com/problems/4-keys-keyboard/description/ 题目: Imagine you have a special ke ...

  3. Oracle存储过程创建及调用

    在大型数据库系统中,有两个很重要作用的功能,那就是存储过程和触发器.在数据库系统中无论是存储过程还是触发器,都是通过SQL 语句和控制流程语句的集合来完成的.相对来说,数据库系统中的触发器也是一种存储 ...

  4. JvisualVm添加远程监控

    一.Weblogic远程监控 1.首先需要在远程的weblogic的域下面,找到/bin/ setDomainEnv.sh ,需要在此文件下加入如下内容: -Dcom.sun.management.j ...

  5. CF884D:Boxes And Balls

    浅谈\(Huffman\)树:https://www.cnblogs.com/AKMer/p/10300870.html 题目传送门:https://codeforces.com/problemset ...

  6. kindeditro.js乱码问题

    kindeditor.js是用于显示新建邮件时的菜单栏的一个插件,比较好用,但是在引入的时候会出现乱码问题,主要有几个方面原因. 1.编码方式不对,要设置成utf8. <script chars ...

  7. 第七篇 PHP编码规范

    当码农多年,始终进步不大,前面说了第一个原因是没有明确的目标:第二个原因是没有养成良好的习惯(即优秀的职业规范). 1)pear 规范 http://pear.php.net/manual/en/st ...

  8. 学习vue

    一,声明模板的时候需要新建示例 如下代码 <div id="app"> <my></my> </div> Vue.component ...

  9. QQ控件时光轴特效总结

    1.插入HTML数据 插入html代码,一般的做法是通过document.getElementById("").innerHTML来实现. 然而在该控件中,它通过JS replac ...

  10. mycat 新增分片和字符集

    执行 select * from travelrecord ,分析Debug日志,说明整个执行逻辑,包括连接获取,连接同步信息,数据合并,数据返回,连接释放 新增一个分片表 T_VOTE (ID,PR ...