Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions longest-substring-without-repeating-characters/delight010.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
func lengthOfLongestSubstring(_ s: String) -> Int {
if s.isEmpty {
return 0
}
var maxLength = 0
var startIndex = 0
var charSet: Set<Character> = []
let charArray = Array(s)

for right in 0..<charArray.count {
while charSet.contains(charArray[right]) {
charSet.remove(charArray[startIndex])
startIndex += 1
}

charSet.insert(charArray[right])
maxLength = max(maxLength, right - startIndex + 1)
}

return maxLength
}
}

61 changes: 61 additions & 0 deletions set-matrix-zeroes/delight010.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class Solution {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저와는 다른 접근법으로 푸셔서 많이 배워갑니다..!!! 공간 복잡도나 시간 복잡도를 올려주셔도 좋을 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가하였습니다!!

func setZeroes(_ matrix: inout [[Int]]) {
var firstRowHasZero = false
var firstColHasZero = false

for col in 0..<matrix[0].count {
if matrix[0][col] == 0 {
firstRowHasZero = true
break
}
}

for row in 0..<matrix.count {
if matrix[row][0] == 0 {
firstColHasZero = true
break
}
}

// marking
for row in 0..<matrix.count {
for col in 0..<matrix[row].count {
if matrix[row][col] == 0 {
matrix[row][0] = 0
matrix[0][col] = 0
}
}
}

// row
for row in 1..<matrix.count {
if matrix[row][0] == 0 {
for col in 0..<matrix[row].count {
matrix[row][col] = 0
}
}
}

// column
for col in 1..<matrix[0].count {
if matrix[0][col] == 0 {
for row in 0..<matrix.count {
matrix[row][col] = 0
}
}
}

if firstRowHasZero {
for col in 0..<matrix[0].count {
matrix[0][col] = 0
}
}

if firstColHasZero {
for row in 0..<matrix.count {
matrix[row][0] = 0
}
}
}
}

13 changes: 13 additions & 0 deletions unique-paths/delight010.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
func uniquePaths(_ m: Int, _ n: Int) -> Int {
let column = Array(repeating: 1, count: n)
var grid: [[Int]] = Array(repeating: column, count: m)
for i in 1..<m {
for j in 1..<n {
grid[i][j] = grid[i - 1][j] + grid[i][j - 1]
}
}
return grid.last!.last!
}
}