
장고 좋아요 기능 구현하기
2022. 10. 13. 17:10
Django 개념
models.py from django.db import models from django.conf import settings # Create your models here. class Article(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) # 이 부분 !!!!!!================================================================================= like_users = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='like_articles') # 이 부분..

장고 커스텀 filter 만들기
2022. 10. 13. 14:47
Django 개념
앱 내에 templatetags이름의 폴더 만들기 -> __init__.py 만들어 주기 -> (예시)my_filter.py파일에 함수 작성 my_filter.py 내부 설정 from atexit import register from django import template register = template.Library() # 간단하게 대문자로 바꿔주기 @register.filter def my_upper(val): return val.upper() + ' RYU' html파일 설정 py파일 이름 로드해주기 변수뒤에 함수명 필터처럼 붙여주기 화면 렌더링 (정상 작동)

리트코드 778 Swim in Rising Water (파이썬)
2022. 10. 10. 20:10
리트코드
https://leetcode.com/problems/swim-in-rising-water/ Swim in Rising Water - 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 (0, 0)에서 (N-1, N-1)로 가는 최단 거리를 찾는 전형적인 다익스트라 알고리즘 문제 풀이 import heapq class Solution(object): def swimInWater(self, grid): N = len(grid) visit = set() minH = [[..

리트코드 1584 Min Cost to Connect All Points (파이썬)
2022. 10. 10. 19:33
리트코드
https://leetcode.com/problems/min-cost-to-connect-all-points/ Min Cost to Connect All Points - 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 전형적인 MST문제이다. 풀이 및 해설(주석) import heapq class Solution(object): def minCostConnectPoints(self, points): N = len(points) adj = { i:[] for i i..

백준 16236 아기 상어 (파이썬)
2022. 10. 9. 21:49
백준
풀이 및 해설(주석) from collections import deque import sys from heapq import heappush, heappop # sys.stdin = open('아기상어.txt', 'r') def find_shark(): for i in range(N): for j in range(N): if arr[i][j] == 9: return i, j def solve(): global size, eat, rst, visit, target Q = deque() # 일단 현재 상어 위치 찾아서 Q에 넣어주고, 상어가 있는 좌표를 방문 처리 sr, sc = find_shark() Q.append((sr, sc)) visit = [[0] * N for _ in range(N)] vis..

리트코드 684 Redundant Connection (파이썬)
2022. 10. 9. 16:05
리트코드
https://leetcode.com/problems/redundant-connection/ Redundant Connection - 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 아이디어 엣지의 정보가 주어지므로 엣지를 순차적으로 순회하며 연결시켜 그래프를 만든다. 그래프를 만들며 싸이클이 생기는 엣지의 정보를 발견하면 그 엣지를 return한다. 풀이 및 해설(주석) class Solution(object): def findRedundantConnection..

리트코드 79 Word Search (파이썬)
2022. 10. 9. 14:57
리트코드
https://leetcode.com/problems/word-search/ Word Search - 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 풀이 및 해설 from collections import defaultdict class Solution(object): def exist(self, board, word): N, M = len(board), len(board[0]) # dfs탐색 하기 전의 사전 작업 단어가 충분하지 않다면, 바로 False를 re..

리트코드 417 Pacific Atlantic Water Flow (파이썬)
2022. 10. 9. 14:20
리트코드
https://leetcode.com/problems/pacific-atlantic-water-flow/ Pacific Atlantic Water Flow - 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(object): d..