Tried to submit as swift, can be compiled in xCode, but fails here.


  • 0
    I

    Code runs in xCode but gets the run time error "Variable column size in 2d array is not supported. Column size expected to be constant size (3) but got size (2)." in OJ.

    Following is my code, actually is there any where just to get the test cases list?

    Thank you guys, and Swift programmers should step out, lol.

    func accountsMerge(_ accounts: [[String]]) -> [[String]] {
            var mAccounts = [(String, Set<String>)]()
            for sa in accounts {
                mAccounts.append((sa[0], Set(Array(sa[1...sa.count - 1]))))
            }
            for i in 0..<mAccounts.count {
                var sa1 = mAccounts[i]
                if sa1.1.isEmpty {
                    continue
                }
                
                for j in 0..<mAccounts.count {
                    var sa2 = mAccounts[j]
                    if (j == i || sa2.1.isEmpty) {
                        continue
                    }
                    if sa1.1.intersection(sa2.1).isEmpty {
                        continue
                    }
                    sa1.1.formUnion(sa2.1)
                    sa2.1.removeAll()
                    mAccounts[i] = sa1
                    mAccounts[j] = sa2
                }
            }
            var result = [[String]]()
            for sa in mAccounts {
                var line = [String]()
                if sa.1.isEmpty { continue }
                line.append(sa.0)
                line.append(contentsOf: Array(sa.1.sorted()))
                result.append(line)
            }
            return result
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.