Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# LeetCode
## Table of Contents
1. Easy
1. 88\. Merge Sorted Array
- [Swift](/easy/swift/88.%20Merge%20Sorted%20Array)
1. 704\. Binary Search
- [Swift](./easy/swift/704_binary_search.swift)
1. Medium
Expand Down
23 changes: 23 additions & 0 deletions easy/swift/88. Merge Sorted Array
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Initially Modified at 01:45 PM on Thu 16 Nov 2023
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of this line.

Last Modified at 01:53 PM on Thu 16 Nov 2023
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of this line.

Create upload-88-merge-sorted-array@github at 2:33 PM on Thu 16 Nov 2023.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of this line.

*/
let numbers1: [Int] = [1, 2, 4] // sorted!
let numbers2: [Int] = [1, 1, 4] // sorted!
var numbers: [Int] = []

var i = 0, j = 0
while i < numbers1.count || j < numbers2.count {
if numbers1[i] == numbers2[j] || numbers1[i] < numbers2[j] {
numbers.append(numbers1[i])
numbers.append(numbers2[j])
}
else {
numbers.append(numbers2[j])
numbers.append(numbers1[i])
}

if i < numbers1.count { i += 1}; if j < numbers2.count { j += 1 }
}

print(numbers)