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 letterCasePermutation(_ S: String) -> [String] { | |
| if S.count == 0 {return [""]} | |
| var results = [String]() | |
| for char in S { | |
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 transpose(_ A: [[Int]]) -> [[Int]] { | |
| let oldRowCount = A.count | |
| let oldColCount = A.first?.count ?? 0 | |
| let newRowCount = oldColCount | |
| let newColCount = oldRowCount | |
| var newRows = [[Int]]() | |
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 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 { |
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 intToRoman(_ num: Int) -> String { | |
| var currentNum = num | |
| var romanNum = "" | |
| while (currentNum >= 1) { | |
| while (currentNum >= 1000) { | |
| romanNum += "M" |
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 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 { |
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
| 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 |
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
| 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 |
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
| img = imread('Lenna.png'); | |
| grayImg = rgb2gray(img); | |
| [imgHeight, imgWidth] = size(grayImg); | |
| % H = fspecial('laplacian'); | |
| % result = imfilter(grayImg,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
| img = imread('computer.JPG'); | |
| imgSize = size(img) % (H, W) | |
| newImgHeight = 418 | |
| newImgWidth = 727 | |
| newImg = zeros(newImgHeight, newImgWidth, 3); | |
| values = [ | |
| 1.0000 | |
| 0.1005 |
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
| % 要先取得原圖的左上, 左下, 右上及右下的點 | |
| leftTopX = 33; | |
| leftTopY = 98; | |
| rightTopX = 760; | |
| rightTopY = 129; | |
| leftDownX = 75; | |
| leftDownY = 508; |