leetcode 썸네일형 리스트형 Container With Most Water - leetcode https://leetcode.com/problems/container-with-most-water/description/ class Solution { func maxArea(_ height: [Int]) -> Int { var max = 0 // 시작 인덱스 var startIndex = 0 // 끝 인덱스 var endIndex = height.count - 1 // 시작 인덱스가 끝 인덱스 보다 작을 때만 반복 while (startIndex < endIndex) { // x축 길이 구하고 let x = abs(startIndex - endIndex) // y축 길이는 두 막대 중 길이가 작은 걸로 let y = min(height[startIndex], height[endIndex]) // 가장.. 더보기 Zigzag Conversion - leetcode https://leetcode.com/problems/zigzag-conversion/description/ class Solution { func convert(_ s: String, _ numRows: Int) -> String { // 지그재그 문자를 저장할 배열 var words: [String] = [String].init(repeating: "", count: numRows) // 입력받은 문자열을 배열로 변환 let input = s.map { $0.description } // 증가할건지 감소할건지를 정하는 변수 var sign: Bool = true // 지그재그 문자를 저장할 배열의 인덱스 var index: Int = 0 // 만약 한 줄이면 문자 그대로 리턴하고 끝냄 if numRo.. 더보기 Add Two Numbers - leetcode https://leetcode.com/problems/add-two-numbers/description/ public class ListNode { public var val: Int public var next: ListNode? public init() { self.val = 0; self.next = nil; } public init(_ val: Int) { self.val = val; self.next = nil; } public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; } } class Solution { func addTwoNumbers(_ l1: ListNode?, _ l2: ListNode?) -> Li.. 더보기 이전 1 다음