본문 바로가기

분류 전체보기264

[코딩 + 알고리즘 완주반] 9일차. 데이터베이스 연동 (SQLite) # 데이터베이스 및 테이블 생성 # 테이블 생성 및 삽입 import sqlite3 import datetime #삽입 날짜 생성 now = datetime.datetime.now() print(now) # 날짜를 스트링으로 변환 nowDatetime = now.strftime('%Y-%m-%d %H:%M:%S') print(nowDatetime) #sqlite3 print(sqlite3.version) print(sqlite3.sqlite_version) # DB 생성 & Auto commit(Rollback) conn = sqlite3.connect('./resource/database.db',isolation_level=None) # cursor c = conn.cursor() print('Curs.. 2021. 3. 23.
[LEET CODE] 328. Odd Even Linked List # Problem Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. The first node is considered odd, and the second node is even, and so on. Note that the relative order inside both the even and odd groups should remain as it was in the input. Constraints: The number of nodes in the linked list i.. 2021. 3. 23.
[LEET CODE] 24. Swap Nodes in Pairs # Problem Given a linked list, swap every two adjacent nodes and return its head. Constraints: The number of nodes in the list is in the range [0, 100]. 0 ListNode: cur = head while cur and cur.next: # 값만 교환 cur.val, cur.next.val = cur.next.val, cur.val cur = cur.next.next return head # Solution 2 - 반복 구조로 스왑 # Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = .. 2021. 3. 23.
[LEET CODE] 2. Add Two Numbers ( 숫자형 리스트 병합하기) # Problem You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Constraints: The number of nodes in each linked list is in the range .. 2021. 3. 22.
[LEET CODE] 206. Reverse Linked List # Problem Given the head of a singly linked list, reverse the list, and return the reversed list. Constraints: The number of nodes in the list is the range [0, 5000]. -5000 ListNode: def reverse(node: ListNode, prev: ListNode = None): if not node: return prev next, node.next = node.next, prev return reverse(next, node) return reverse(head) # Solution 2 - 반복 구조로 뒤집기 # Definition for singly-linked.. 2021. 3. 22.
[LEET CODE] 21. Merge Two Sorted Lists ( 연산자 우선순위, 변수 스왑) # Problem Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists. Constraints: The number of nodes in both lists is in the range [0, 50]. -100 ListNode: if (not l1) or (l2 and l1.val > l2.val): l1, l2 = l2, l1 # 작은 값을 계속 l1에 연결시킨다. if l1: l1.next = self.mergeTwoLists(l1.next, l2) return l1 # 연산자 우선순위 우선순위 연산자 설명.. 2021. 3. 22.
반응형