GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/code/lc242.java at master · mJackie/leetcode Expand file tree/ Copy pathlc242.javaMore file actions 23 lines (23 loc) · 660 Bytes / Copy pathlc242.javaFile metadata and controls23 lines (23 loc) · 660 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 package code; /* * 242. Valid Anagram * 题意:字符串t是否为s打乱后的重排列 * 难度:Easy * 分类:Hash Table, Sort * 思路:hash table 计算即可,<0了直接返回false * Tips:和重排列那题联系一下 lc46 */ public class lc242 { public boolean isAnagram(String s, String t) { if(s.length()!=t.length()) return false; int[] chs = new int[26]; for(int i=0; i<s.length(); i++){ chs[s.charAt(i)-'a']++; } for(int i=0; i<t.length(); i++){ chs[t.charAt(i)-'a']--; if(chs[t.charAt(i)-'a']<0) return false; } return true; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |