Review Swift codes (#1150)

* feat(swift): review for chapter_computational_complexity

* feat(swift): review for chapter_data_structure

* feat(swift): review for chapter_array_and_linkedlist

* feat(swift): review for chapter_stack_and_queue

* feat(swift): review for chapter_hashing

* feat(swift): review for chapter_tree

* feat(swift): add codes for heap article

* feat(swift): review for chapter_heap

* feat(swift): review for chapter_graph

* feat(swift): review for chapter_searching

* feat(swift): review for chapter_sorting

* feat(swift): review for chapter_divide_and_conquer

* feat(swift): review for chapter_backtracking

* feat(swift): review for chapter_dynamic_programming

* feat(swift): review for chapter_greedy

* feat(swift): review for utils

* feat(swift): update ci tool

* feat(swift): trailing closure

* feat(swift): array init

* feat(swift): map index
This commit is contained in:
nuomi1
2024-03-20 21:15:39 +08:00
committed by GitHub
parent 300a781fab
commit 7359a7cb4b
55 changed files with 293 additions and 224 deletions

View File

@@ -67,15 +67,15 @@ func editDistanceDP(s: String, t: String) -> Int {
let m = t.utf8CString.count
var dp = Array(repeating: Array(repeating: 0, count: m + 1), count: n + 1)
//
for i in stride(from: 1, through: n, by: 1) {
for i in 1 ... n {
dp[i][0] = i
}
for j in stride(from: 1, through: m, by: 1) {
for j in 1 ... m {
dp[0][j] = j
}
//
for i in stride(from: 1, through: n, by: 1) {
for j in stride(from: 1, through: m, by: 1) {
for i in 1 ... n {
for j in 1 ... m {
if s.utf8CString[i - 1] == t.utf8CString[j - 1] {
//
dp[i][j] = dp[i - 1][j - 1]
@@ -94,16 +94,16 @@ func editDistanceDPComp(s: String, t: String) -> Int {
let m = t.utf8CString.count
var dp = Array(repeating: 0, count: m + 1)
//
for j in stride(from: 1, through: m, by: 1) {
for j in 1 ... m {
dp[j] = j
}
//
for i in stride(from: 1, through: n, by: 1) {
for i in 1 ... n {
//
var leftup = dp[0] // dp[i-1, j-1]
dp[0] = i
//
for j in stride(from: 1, through: m, by: 1) {
for j in 1 ... m {
let temp = dp[j]
if s.utf8CString[i - 1] == t.utf8CString[j - 1] {
//