https://github.com/sustainable-git/coding-test
https://github.com/sustainable-git/coding-test
baekjoon-online-judge cheatsheet codility hackerrank programmers-online-judge
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/sustainable-git/coding-test
- Owner: sustainable-git
- Created: 2021-06-03T04:06:56.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-12T01:43:02.000Z (7 months ago)
- Last Synced: 2025-01-10T17:23:46.476Z (4 months ago)
- Topics: baekjoon-online-judge, cheatsheet, codility, hackerrank, programmers-online-judge
- Language: Swift
- Homepage:
- Size: 284 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Swift Algorithm
## Contents
### String
- Adding
```swift
var sample = "Hello"
sample += " World" // sample == "Hello World"
sample.append("!") // sample == "Hello World!"
```
- Accessing String Element
```swift
let name = "Marie Curie"
let firstSpace = name.firstIndex(of: " ") ?? name.endIndex
let firstName = name[..### Regular Expression
```swift
func isMatched(target: String, pattern: String) -> Bool {
let patternString = "^" + pattern.replacingOccurrences(of: "*", with: "[a-zA-Z0-9]") + "$" // "^": start, "$": end
let regex = try? NSRegularExpression(pattern: patternString)
return regex?.firstMatch(in: target, options: [], range: NSRange(location: 0, length: target.count)) != nil
}
```