Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 6 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Sep 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
优化 242. 有效的字母异位词 Java解法
  • Loading branch information
RyouMon committed Aug 30, 2022
commit 3f96750bece9167e25e52a61c1f52cdcdecdb8ea
20 changes: 13 additions & 7 deletions problems/0242.有效的字母异位词.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,24 @@ public:

Java:
```java
/**
* 242. 有效的字母异位词 字典解法
* 时间复杂度O(m+n) 空间复杂度O(1)
*/
class Solution {
public boolean isAnagram(String s, String t) {

int[] record = new int[26];
for (char c : s.toCharArray()) {
record[c - 'a'] += 1;

for (int i = 0; i < s.length(); i++) {
record[s.charAt(i) - 'a']++;
}
for (char c : t.toCharArray()) {
record[c - 'a'] -= 1;

for (int i = 0; i < t.length(); i++) {
record[t.charAt(i) - 'a']--;
}
for (int i : record) {
if (i != 0) {

for (int count: record) {
if (count != 0) {
return false;
}
}
Expand Down

AltStyle によって変換されたページ (->オリジナル) /