-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Bug Report for https://neetcode.io/problems/insertionSort
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
The errors that are showing up are not accurate and instead are random. for this input:
// Definition for a pair
// class Pair {
// var key: Int
// var value: String
// init(_ key: Int, _ value: String) {
// self.key = key
// self.value = value
// }
// }
class Solution {
static func insertionSort(_ pairs: inout [Pair]) -> [[Pair]] {
var res = [Pair]
for i in 0..<pairs.count {
if i + 1 < pairs.count && pairs[i].key > pairs[i + 1].key {
let tmp = pairs[i]
pairs[i] = pairs[i + 1]
pairs[i + 1] = tmp
}
for i in 0..<pairs.count {
res.append([pairs[i]])
}
}
return res
}
}
main.swift:122:35: error: static member 'insertionSort' cannot be used on instance of type 'Solution'
120 | let s = Solution()
121 | var input = parseInput(line)
122 | let str = parseOutput(s.insertionSort(&input))
| `- error: static member 'insertionSort' cannot be used on instance of type 'Solution'
123 |
124 | print("===USE_THIS_LINE_TO_SEPARATE_USER_LOGS_AND_TEST_CASE_OUTPUT_394w8389wry89areisJAHSDBHJBdsjnkzbdcifbscidfbasekhfgiJHBG===")
I get this error but on playgrounds I get a different error:
import Cocoa
// Definition for a pair
class Pair {
var key: Int
var value: String
init(_ key: Int, _ value: String) {
self.key = key
self.value = value
}
}
var pairs: [Pair] = [Pair(5, "apple"), Pair(2, "banana"), Pair(9, "cherry")]
class Solution {
static func insertionSort(_ pairs: inout [Pair]) -> [[Pair]] {
var res = [Pair]
for i in 0..<pairs.count {
if i + 1 < pairs.count && pairs[i].key > pairs[i + 1].key {
let tmp = pairs[i]
pairs[i] = pairs[i + 1]
pairs[i + 1] = tmp
}
for i in 0..<pairs.count {
res.append([pairs[i]])
}
}
return res
}
}
print(Solution.insertionSort(&pairs)
)
[[__lldb_expr_95.Pair], [__lldb_expr_95.Pair], [__lldb_expr_95.Pair], [__lldb_expr_95.Pair], [__lldb_expr_95.Pair], [__lldb_expr_95.Pair], [__lldb_expr_95.Pair], [__lldb_expr_95.Pair], [__lldb_expr_95.Pair]]
this isnt even a error just a different output