Skip to content

Instantly share code, notes, and snippets.

@NigelJu
NigelJu / 784. Letter Case Permutation.swift
Created April 3, 2019 08:04
784. Letter Case Permutation
class Solution {
func letterCasePermutation(_ S: String) -> [String] {
if S.count == 0 {return [""]}
var results = [String]()
for char in S {
@NigelJu
NigelJu / TransposeMatrix2.swift
Created March 31, 2019 04:54
Transpose Matrix2
class Solution {
func transpose(_ A: [[Int]]) -> [[Int]] {
let oldRowCount = A.count
let oldColCount = A.first?.count ?? 0
let newRowCount = oldColCount
let newColCount = oldRowCount
var newRows = [[Int]]()
@NigelJu
NigelJu / Transpose Matrix1.swift
Created March 31, 2019 04:37
Transpose Matrix1
class Solution {
func transpose(_ A: [[Int]]) -> [[Int]] {
let oldRowCount = A.count
let oldColCount = A.first?.count ?? 0
var newMatrix = [[Int]](repeating: [Int](repeatElement(0, count: oldRowCount)), count: oldColCount)
for rowIndex in 0 ..< oldRowCount {
for colIndex in 0 ..< oldColCount {
@NigelJu
NigelJu / 12_IntegerToRoman.swift
Created March 30, 2019 12:25
12_IntegerToRoman
class Solution {
func intToRoman(_ num: Int) -> String {
var currentNum = num
var romanNum = ""
while (currentNum >= 1) {
while (currentNum >= 1000) {
romanNum += "M"
@NigelJu
NigelJu / CountPrimes2.swift
Created March 29, 2019 14:34
CountPrimes2
class Solution {
func countPrimes(_ n: Int) -> Int {
if n <= 2 { return 0 }
var primeTable = [Bool](repeating: true, count: n)
var primeCount = 1
var currentNum = 3
while currentNum < n {
import UIKit
class Solution {
func countPrimes(_ n: Int) -> Int {
if n <= 2 { return 0 }
var primeTable = [Bool](repeating: true, count: n)
for index in 2 ..< n {
var base = 2
while index * base < n {
primeTable[index * base] = false
base += 1
@NigelJu
NigelJu / dip_hw4.m
Last active January 4, 2019 13:27
dip_hw4.m
img = imread('lenna.png');
grayImg = im2double(rgb2gray(img));
[height, width] = size(grayImg);
impluseNoiseImg = double(zeros(height, width));
% impluse (salt & pepper) noise
for h = 1: height
@NigelJu
NigelJu / DIP_HW3.m
Last active December 11, 2018 09:05
DIP_HW3.m
img = imread('Lenna.png');
grayImg = rgb2gray(img);
[imgHeight, imgWidth] = size(grayImg);
% H = fspecial('laplacian');
% result = imfilter(grayImg,H);
img = imread('computer.JPG');
imgSize = size(img) % (H, W)
newImgHeight = 418
newImgWidth = 727
newImg = zeros(newImgHeight, newImgWidth, 3);
values = [
1.0000
0.1005
% 要先取得原圖的左上, 左下, 右上及右下的點
leftTopX = 33;
leftTopY = 98;
rightTopX = 760;
rightTopY = 129;
leftDownX = 75;
leftDownY = 508;