본문 바로가기 메뉴 바로가기

Peppo

프로필사진
  • 글쓰기
  • 관리
  • 태그
  • 방명록
  • RSS

Peppo

검색하기 폼
  • 분류 전체보기 (221)
    • Story (13)
    • iOS (143)
      • Error (11)
    • 알고리즘 (43)
    • ETC (7)
    • React-Native (0)
    • CS (Computer science) (3)
  • 방명록

Swift Leetcode (4)
[Swift 알고리즘] - Valid Parentheses (LeetCode)

https://leetcode.com/problems/valid-parentheses/description/ 주어진 문자열(s)가 유효한지 확인 모든 열려있는 괄호는 같은 타입의 괄호로 닫혀야 함 내 풀이 class Solution { func isValid(_ s: String) -> Bool { guard s.count > 1 else { return false } var stack = [Character]() for char in s { switch char { case "(", "{", "[": stack.append(char) case ")": if stack.last == "(" { stack.removeLast() } else { return false } case "}": if stack...

알고리즘 2023. 8. 24. 09:39
[Swift 알고리즘] - Best Time to Buy and Sell Stock (LeetCode)

https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ 일별로 주식 가격이 주어졌을 때, 최대 이익을 구하기 내 풀이 class Solution { func maxProfit(_ prices: [Int]) -> Int { guard prices.count > 1 else { return 0 } var result: [Int] = [] for price in prices { for j in 1.. 0 { var profit = prices[j] - price print(prices[j], "-", price, "=", prices[j] - price) result.append(profit) } } } return result.max() ?? 0 } ..

알고리즘 2023. 8. 22. 09:08
[Swift 알고리즘] - Two Sum (LeetCode)

https://leetcode.com/problems/two-sum/ 정수의 배열로 이루어진 nums로 각각 더해서 target의 값과 같으면 해당 index들을 리턴 내 풀이 class Solution { func twoSum(_ nums: [Int], _ target: Int) -> [Int] { var result: [Int] = [] for (idx, num) in nums.enumerated() { for idx2 in (idx + 1) ..< nums.count { if num + nums[idx2] == target { return [idx, idx2] } } } return result } } Solution().twoSum([2, 7, 11, 15], 9) enumerated()를 이용해..

알고리즘 2023. 8. 17. 08:31
[Swift 알고리즘] - Valid Anagram (LeetCode)

https://leetcode.com/problems/valid-anagram/ 내 풀이 class Solution { func isAnagram(_ s: String, _ t: String) -> Bool { var sortedS = s.sorted() var sortedT = t.sorted() return sortedS == sortedT ? true : false } } Solution().isAnagram("anagram", "nagaram") s, t를 정렬해서 두 string의 순서들을 똑같이 만듬. `==` (비교연산자)를 사용해 s, t를 비교하여 같으면 true를, 다르면 false를 리턴 다른사람의 풀이 class Solution { func isAnagram(_ s: String, ..

알고리즘 2023. 8. 16. 08:53
이전 1 다음
이전 다음
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
  • Peppo's Github
TAG
  • swift protocol
  • swift property
  • swift reduce
  • RIBs tutorial
  • 원티드 프리온보딩
  • Swift 프로퍼티
  • Swift 프로그래머스
  • swift programmers
  • Swift inout
  • ios
  • Swift RIBs
  • RTCCameraVideoCapturer
  • removeLast()
  • Class
  • Swift 알고리즘
  • Swift joined
  • Swift final
  • iOS error
  • Swift 내림차순
  • Swift init
  • swift (programmers)
  • Swift ModernRIBs
  • Swift Error Handling
  • Combine: Asynchronous Programming with Swift
  • Swift Leetcode
  • 2023년 회고
  • swift 고차함수
  • Swift
  • CS 네트워크
  • Swift joined()
more
«   2025/08   »
일 월 화 수 목 금 토
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함

Blog is powered by Tistory / Designed by Tistory

티스토리툴바