Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: doocs/leetcode
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: klever34/leetcode
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: swift-impl-lcof-50
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on May 28, 2024

  1. Swift implementation for LCOF 50

    klever34 committed May 28, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    klever34 Lanre Adedara
    Copy the full SHA
    a3b677b View commit details
  2. style: format code and docs with prettier

    yanglbme authored and idoocs committed May 28, 2024
    Copy the full SHA
    66c54f2 View commit details
Showing with 41 additions and 0 deletions.
  1. +23 −0 lcof/面试题50. 第一个只出现一次的字符/README.md
  2. +18 −0 lcof/面试题50. 第一个只出现一次的字符/Solution.swift
23 changes: 23 additions & 0 deletions lcof/面试题50. 第一个只出现一次的字符/README.md
Original file line number Diff line number Diff line change
@@ -193,6 +193,29 @@ public class Solution {
}
```

#### Swift

```swift
class Solution {
func firstUniqChar(_ s: String) -> Character {
var count = [Int](repeating: 0, count: 26)
let aAsciiValue = Int(Character("a").asciiValue!)

for char in s {
count[Int(char.asciiValue!) - aAsciiValue] += 1
}

for char in s {
if count[Int(char.asciiValue!) - aAsciiValue] == 1 {
return char
}
}

return " "
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
18 changes: 18 additions & 0 deletions lcof/面试题50. 第一个只出现一次的字符/Solution.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
func firstUniqChar(_ s: String) -> Character {
var count = [Int](repeating: 0, count: 26)
let aAsciiValue = Int(Character("a").asciiValue!)

for char in s {
count[Int(char.asciiValue!) - aAsciiValue] += 1
}

for char in s {
if count[Int(char.asciiValue!) - aAsciiValue] == 1 {
return char
}
}

return " "
}
}