Skip to content

Instantly share code, notes, and snippets.

@NigelJu
NigelJu / hw2_2.c
Created November 12, 2018 08:17
hw2_2.c
//
// main.c
// HW2
//
// Created by Nigel on 2018/11/1.
// Copyright © 2018 Nigel. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
@NigelJu
NigelJu / bilinearInterpolation.py
Created November 5, 2018 06:27
bilinearInterpolation.py
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)
@NigelJu
NigelJu / nearestNeighborInterpolation.py
Created November 5, 2018 06:26
nearestNeighborInterpolation.py
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)]
@NigelJu
NigelJu / hw2.c
Created November 3, 2018 04:12
hw2.c
//
// main.c
// HW2
//
// Created by Nigel on 2018/11/1.
// Copyright © 2018 Nigel. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
@NigelJu
NigelJu / Middle of the Linked List2.swift
Created October 31, 2018 18:23
Middle of the Linked List
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
}
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)
@NigelJu
NigelJu / LeetCode 441. Arranging CoinsLoop.swift
Last active August 15, 2018 13:07
LeetCode 441. Arranging CoinsLoop.swift
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{
@NigelJu
NigelJu / LeetCode 118. Pascal's Triangle.swift
Created August 7, 2018 13:20
LeetCode 118. Pascal's Triangle.swift
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 {
@NigelJu
NigelJu / charts-lineCharts-Do Not Show Lower Value.swift
Created July 22, 2018 07:53
charts-lineCharts-Do Not Show Lower Value.swift
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 {
@NigelJu
NigelJu / Permutations(swift).swift
Created July 18, 2018 14:22
Permutations(swift).swift
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)