This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func removeElement(_ nums: inout [Int], _ val: Int) -> Int { | |
| var left = 0 | |
| var right = nums.count | |
| while left < right { | |
| if nums[left] == val { | |
| nums[left] = nums[right - 1] | |
| right -= 1 | |
| } else { | |
| left += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func buddyStrings(_ A: String, _ B: String) -> Bool { | |
| if A.count != B.count { return false } | |
| var A = Array(A), B = Array(B) | |
| if A == B { | |
| return A.count > Set(A).count | |
| } else { | |
| return differentLetters(A, B) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func hammingDistance(_ x: Int, _ y: Int) -> Int { | |
| var hammingDistance = x ^ y | |
| var counter = 0 | |
| while hammingDistance > 0 { | |
| hammingDistance &= (hammingDistance - 1) | |
| counter += 1 | |
| } | |
| return counter | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func singleNumber(_ nums: [Int]) -> Int { | |
| var set = Set<Int>() | |
| for number in nums { | |
| if !set.contains(number) { | |
| set.insert(number) | |
| } else { | |
| set.remove(number) | |
| } | |
| } | |
| return set.first ?? 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct VerticalGrid: View { | |
| var columns: [GridItem] = | |
| Array(repeating: .init(.flexible()), count: 2) | |
| var body: some View { | |
| NavigationView { | |
| ScrollView(.vertical) { | |
| LazyVGrid(columns: columns) { | |
| ForEach((1...18), id: \.self) { number in | |
| ImageView(number: number) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct HorizontalGrid: View { | |
| var rows: [GridItem] = | |
| Array(repeating: .init(.flexible()), count: 3) | |
| var body: some View { | |
| NavigationView { | |
| ScrollView(.horizontal) { | |
| LazyHGrid(rows: rows) { | |
| ForEach((1...18), id: \.self) { number in | |
| ImageView(number: number) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct ContentView: View { | |
| @State private var currentTab: Int = 0 | |
| var body: some View { | |
| TabView(selection: $currentTab) { | |
| VerticalGrid() | |
| .tabItem { | |
| Image(systemName: "rectangle.grid.3x2") | |
| Text("Vertical") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct MainView : View { | |
| @State private var currentTab: Int = 1 | |
| var body: some View { | |
| TabView(selection: $currentTab) { | |
| RGBView() | |
| .tabItem { | |
| Image(systemName: "circle.grid.hex") |