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
| // | |
| // main.c | |
| // HW2 | |
| // | |
| // Created by Nigel on 2018/11/1. | |
| // Copyright © 2018 Nigel. All rights reserved. | |
| // | |
| #include <stdio.h> | |
| #include <stdlib.h> |
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
| def bilinearInterpolation(image): | |
| newHeight = image.shape[0] * SCALE | |
| newWidth = image.shape[1] * SCALE | |
| channels = image.shape[2] | |
| newImage = np.zeros((newHeight, newWidth, channels)) | |
| for height in range(0, newHeight): | |
| for width in range(0, newWidth): | |
| newWidthHeader = math.floor(width / SCALE) | |
| newHeightHeader = math.floor(height / SCALE) |
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
| def nearestNeighborInterpolation(image): | |
| newHeight = image.shape[0] * SCALE | |
| newWidth = image.shape[1] * SCALE | |
| channels = image.shape[2] | |
| newImage = np.zeros((newHeight, newWidth, channels)) | |
| for width in range(0, newWidth): | |
| for height in range(0, newHeight): | |
| newImage[height, width] = image[int(height / SCALE), | |
| int(width / SCALE)] |
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
| // | |
| // main.c | |
| // HW2 | |
| // | |
| // Created by Nigel on 2018/11/1. | |
| // Copyright © 2018 Nigel. All rights reserved. | |
| // | |
| #include <stdio.h> | |
| #include <stdlib.h> |
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
| class Solution { | |
| func middleNode(_ head: ListNode?) -> ListNode? { | |
| var fastNode = head | |
| var slowNode = head | |
| while fastNode != nil && fastNode?.next != nil { | |
| fastNode = fastNode?.next?.next | |
| slowNode = slowNode?.next | |
| } |
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
| class Solution { | |
| func middleNode(_ head: ListNode?) -> ListNode? { | |
| let nodeCount = getNodeCount(nodeCount: 1, node: head) | |
| guard nodeCount > 0 else { return nil } | |
| if nodeCount == 1 { return head } | |
| // print(nodeCount) |
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
| class Solution { | |
| func arrangeCoins(_ n: Int) -> Int { | |
| if n == 0 { return 0 } | |
| var remainderConins = n | |
| for index in 1 ... n { | |
| remainderConins -= index | |
| if remainderConins == 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
| class Solution { | |
| func generate(_ numRows: Int) -> [[Int]] { | |
| if numRows == 0 { return [] } | |
| var results = [[Int]]() | |
| for outsideIndex in 1 ... numRows { | |
| var insideValues = [Int]() | |
| for insideIndex in 1 ... outsideIndex { |
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
| var clearEntries = [ChartDataEntry]() | |
| var entries2 = [ChartDataEntry]() | |
| let values: [Double] = [0, 3, 4, 0, 1, 0, 9] | |
| for x in 0 ..< values.count { | |
| let y = values[x] | |
| let defaultDataEntry = ChartDataEntry(x: Double(x), y:y) | |
| clearEntries.append(defaultDataEntry) | |
| } | |
| for x in 0 ..< values.count { |
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
| class Solution { | |
| func permute(_ nums: [Int]) -> [[Int]] { | |
| if nums.count == 1 { return [nums] } | |
| var result = [[Int]]() | |
| for num in nums { | |
| let index = nums.index(of: num)! | |
| var newNums = nums | |
| newNums.remove(at: index) |