Movatterモバイル変換


[0]ホーム

URL:


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

Commit63dfef2

Browse files
Merge pull requestneetcode-gh#59 from chandra9302/patch-6
Create 242-Valid-Anagrams.swift
2 parents8fcd768 +a16a7bc commit63dfef2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎swift/242-Valid-Anagram.swift‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Question Link: https://leetcode.com/problems/valid-anagram/
3+
*/
4+
5+
classValidAnagram{
6+
func isAnagram(_ s:String, _ t:String)->Bool{
7+
if s.count!= t.count{
8+
returnfalse
9+
}
10+
varcountS=[Int:Int]()
11+
varcountT=[Int:Int]()
12+
letsChars=Array(s)
13+
lettChars=Array(t)
14+
foriin0..<sChars.count{
15+
countS[Int(sChars[i].asciiValue!)]=1+ countS[Int(sChars[i].asciiValue!), default:0]
16+
countT[Int(tChars[i].asciiValue!)]=1+ countT[Int(tChars[i].asciiValue!), default:0]
17+
}
18+
for(key, _)in countS{
19+
ifcountS[key]!=countT[key, default:0]{
20+
returnfalse
21+
}
22+
}
23+
returntrue
24+
}
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp