Compile Error on swift

  • 0

    My code work on Xcode, but it doesn't work at here, would someone tell me what is the problem of my code. thanks a lot, below is my code:

    class Solution {
        func twoAdd(_ nums: [Int], _ target: Int) -> [Int]{
            var indict = [Int]()
            for num in nums{
                let complement = target - num
                var firstIndex = 0
                var secondIndex = 0
                if let index = nums.index(of: num){
                    firstIndex = index
                for n in nums[firstIndex + 1 ..< nums.count]{
                    //get the complement, retrieve the index of the complement
                    if n == complement{
                        if let index = nums.index(of: n){
                            secondIndex = index
                        //add the element to the indict and exit the loop
                        return indict
            return indict

Log in to reply

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