본문 바로가기

반응형

전체 글

(168)
Timer, Countdown 타이머를 구현하고 싶을때는 Timer를 사용하면 된다. timer.invalidate() timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateCounter), userInfo: nil, repeats: true) @objc func updateCounter() { //example functionality if counter > 0 { print("\(counter) seconds to the end of the world") counter -= 1 } else { timer.invalidate() titleLabel.text = "Done!" } } 한개의 타이머만 작동시키기 위해서는 invalid..
[Python] 226. 트리 데칼코마니 leetcode.com/problems/invert-binary-tree/ Invert Binary Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 바이너리 트리를 데칼코마니 시키는 것을 말한다. 좌측과 우측을 바꾸는 문제 재귀적으로 생각해서 현재 트리의 좌측과 우측을 구한다음 그것을 현재 트리의 좌측-우측, 우측-좌측 이렇게 매핑 시켜주면 된다 class Solution: def invertTree(self, root: TreeNode) -> Tre..
[Python] 206. 링크드 리스트 거꾸로 만들기 class Solution: def reverseList(self, head: ListNode) -> ListNode: if not head: return None stk = [] while head != None: stk.append(head.val) head = head.next new_head = ListNode() cur = new_head while stk: cur.val = stk.pop() if stk: cur.next = ListNode() cur = cur.next return new_head 스택을 이용하는 방법이다. 스택에 값을 하나씩 넣고 빼게 되면 가장 나중 것이 처음에 빠지는 원리는 이용하였다. 다음에는 재귀로 풀 수 있는 방법을 고민해봐야겠다.
[Mysql] 이전날보다 낮은 온도인 id 찾기 바로 이전날보다 낮은 온도인 id를 찾는 방법 select w2.id from weather w1 join weather w2 where date_add(w1.recorddate,interval 1 day) = w2.recorddate and w1.temperature < w2.temperature date_add()를 쓰면 찾을 수 있다. date_add(date, interval 0 day) 이런식으로 쓸 수 있다.
[Mysql] 중복된 값 지우기 delete를 이용하여 중복된 값을 지우는 방법 delete a from person a join person b where a.id > b.id and a.email = b.email
[Mysql] 2번째로 높은 값 찾기 select ifnull((select distinct salary from Employee order by salary desc limit 1,1),null) as SecondHighestSalary 두번째로 높은 값을 찾기 위해 정렬과 중복값을 제외한다. 그 이후 limit을 통해 두번째 값만을 select로 찾는다 하지만 여기서 고려해야할 사항이 두번째 row가 없을 경우이다. 이 경우를 대비하여 ifnull 안에 select를 넣고 이 값이 null일 경우 null을 출력하게 한다. https://leetcode.com/problems/second-highest-salary/ Second Highest Salary - LeetCode Level up your coding skills and qui..
[Mysql] 중복된 값 찾기 중복된 값을 찾는 문제이다. select email from person group by email having count(email) > 1 그룹으로 묶고 숫자를 셋을 때 갯수가 2개 이상이면 중복이 발생했다는 것을 알 수 있다. https://leetcode.com/problems/duplicate-emails/ Duplicate Emails - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com
그래프에서 사이클 찾는 법 해시 테이블 이용 노드를 해시 테이블에 넣고 그 노드가 다시 방문하면 사이클 존재 투 포인터 slow = head fast = head.next slow는 한칸씩 전진, fast는 두칸씩 전진한다 fast가 slow와 만나면 사이클 존재 만나지 않고 fast가 null 혹은 fast.next가 null이라면 사이클 존재 x https://leetcode.com/problems/linked-list-cycle/ Linked List Cycle - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next intervi..