전체 글

헛둘헛둘
· 생각정리
보호되어 있는 글입니다.
https://leetcode.com/problems/max-area-of-island/ Max Area of Island - LeetCode Can you solve this real interview question? Max Area of Island - You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are su leetcode.com # 문제 # 예시 Example 1: Input: grid = [[0,0,1,0,0,0..
파이썬에서 클래스를 생성할 때, 모든 메소드의 첫 인자를 "self" 라는 키워드를 놓습니다. 이유는 무엇일까요? class Person: def __init__(self, name, job): self.name = name self.job = job def introduce(self): return f"내 이름은 {self.name}, {self.job}이죠" 라고 두었을 때 p = Person("코난", "탐정") print(p.introduce()) 내 이름은 코난, 탐정이죠 이런 결과가 나온다. 여기서 self는 "인스턴스 자기 자신을 의미" 합니다. 그림으로 나타내면 다음과 같다. 여기서 __init__ 의 매개변수 self에 들어가는 값은 Person이라 할 수 있습니다. self는 그러면 p..
https://leetcode.com/problems/keys-and-rooms/ Keys and Rooms - LeetCode Can you solve this real interview question? Keys and Rooms - There are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key. Whe leetcode.com # 문제 There are n rooms labeled from 0 to n - 1 and all th..
combinations, permutations 문제를 풀다가 생긴 문제이다. 조합, 순열의 결과 값은 튜플형태로 나온다. 예를 들어, from itertools import combinations, permutations import sys num = sys.stdin.readline().rstrip() x = [num[i] for i in range(len(num))] permus = [] for i in range(1, len(x)+1): permu = list(permutations(x,i)) print(permu) 위코드는 "리스트에 해당하는 모든 순열"을 구하는 코드이다. input output 127 [('1',), ('2',), ('7',)] [('1', '2'), ('1', '7'), (..
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXO72aaqPrcDFAXS SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com SSAFY 알고리즘 정기스터디 2번째, 알고리즘 리뷰 # 코드 def pel_check(n): n = str(n) middle_num = len(n)//2 # 중간 index if len(n)%2 == 1: # 홀수라면 n = n[0:middle_num] + n[middle_num+1:] # 중간제거 result = 0 # 펠림드롬 검사 if n[0:middle_num] == n[middle_num..