[String] Add Solution to Buddy Strings - #262
Conversation
[String]Add Solution to Buddy Strings
soapyigu
left a comment
There was a problem hiding this comment.
Hi thanks for the contribution! Could you also update the Progress session in README file?
|
Hi soapyigu, thanks for your reply. All resolved as requested, please review again. Thanks. |
| * Memory Usage: 23.3 MB, less than 100.00% of Swift online submissions for Buddy Strings. | ||
| */ | ||
|
|
||
| class BuddyStrings { |
There was a problem hiding this comment.
Probably you don't want the whitespace before class.
| @@ -0,0 +1,38 @@ | |||
| /** | |||
There was a problem hiding this comment.
It's strange that this file doesn't have a .swift file extension. However, you included .swift in the README. I believe that the link is broken.
| /** | ||
| * Question Link: https://leetcode.com/problems/buddy-strings/ | ||
| * Primary idea: | ||
| 1. return false/tru for absolute cases |
There was a problem hiding this comment.
Minor, there is a typo: return false/true.
| if aLength != bLength || aLength == 0 { | ||
| return false | ||
| } | ||
| if A == B && Array(Set(A)).count != aLength { |
There was a problem hiding this comment.
You don't have to convert the Set to Array to get the count, right?
| } | ||
| let aArray = Array(A), bArray = Array(B) | ||
| var diff = [Character]() | ||
| for index in 0...aLength-1 { |
There was a problem hiding this comment.
I would say, a better practice in Swift would be:
for index in 0..<aLength|
Could you please resolve the merge conflict? |
No description provided.