Swift solution.


  • 1
    I
    1. first, create a new int array with order (newAr)
    2. second, setup newAr's number in nums equal 0.
    3. find the number in newAr, if not equal 0, then pick up and return.
      But I think it has better way to solve it....
    class Solution {
        func findDisappearedNumbers(_ nums: [Int]) -> [Int] {
            var newAr = [Int]()
            if nums.count < 2{return newAr}
            
            for i in 1...nums.count {
                newAr.append(i)
            }
            for i in 0...nums.count-1 {
                newAr[nums[i]-1] = 0
            }
            var returnAr = [Int]()
            for i in 0...newAr.count-1{
                if newAr[i] != 0 {
                    returnAr.append(newAr[i])  
                }
            }
            return returnAr;  
        }
    }
    

Log in to reply
 

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