GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/code/lc242.java at master · mJackie/leetcode

Expand file tree

/

lc242.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
23 lines (23 loc) · 660 Bytes
/

lc242.java

Copy path

File metadata and controls

23 lines (23 loc) · 660 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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.