본문 바로가기
반응형

전체 글 목록571

[파이썬 python] 리스트 list, 딕셔너리 dictionary 주요 메소드 예제 개인 공부를 위해 모았으며 별도의 설명은 생략 # list len(a) #O(1) a[i] #O(1) a[i:j] #O(k) elem in a #O(n) a.count(elem) #O(n) a.index(elem) #O(n) a.append(elem) #O(1) a.insert(idx, elem) #O(n) a.pop() #O(1) a.pop(0) #O(n) del a[i] #O(n) a.remove(elem) #O(n) a.sort() #O(nlogn) min(a)/max(a) #O(n) a.reverse() #O(n) ## dict len(a) #O(1) a[key] #O(1) a[key] = value #O(1) key in a #O(1) del a['key'] ## dictionary iterat.. 2021. 4. 17.
[프로그래머스 programmers] 네트워크 문제풀이 programmers.co.kr/learn/courses/30/lessons/43162 코딩테스트 연습 - 네트워크 네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있 programmers.co.kr dfs문제이므로 dfs로 접근하였다. 순차적으로 탐색하되 이미 탐색을 완료한 곳이면 즉시 탐색을 중단하고, 탐색하지 않은 곳이면 탐색 목록에 추가시키며 끝까지 탐색한다. 이후 solution 함수에서 탐색 목록에 없었던 곳을 탐색하였다면 그때마다 answer에 1을 더해준다. answer = 0 def solution(n, computers): global answer .. 2021. 4. 16.
[프로그래머스 programmers] 타겟 넘버 문제풀이 programmers.co.kr/learn/courses/30/lessons/43165 코딩테스트 연습 - 타겟 넘버 n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 있습니다. -1+1+1+1+1 = 3 +1-1+1+1+ programmers.co.kr dfs 문제이므로 dfs로 접근하였다. 부호는 어차피 +또는 -이기때문에 두가지 경우에 대하여 깊이탐색을 실시하고 말단 노드까지 탐색한 뒤 sum이 target과 같다면 경우의 수를 추가하는 방식. def solution(numbers, target): def dfs(sum, idx): if idx == len(number.. 2021. 4. 16.
[알고리즘 algorithm] 비트 연산과 비트 조작 출처: 박상길 지음, 정진호 일러스트, 책만, 2020(https://www.onlybook.co.kr/entry/algorithm-interview) - 부울 연산자 >>> True and False False >>> True or False True >>> not True False and, or, not은 기본 부울 연산자로, 이들을 조합하여 다른 보조 연산을 만들어 내는데, XOR 연산이 대표적인 보조 연산에 해당한다. >>> x = y = True >>> (x and not y) or (not x and y) False - 비트 연산자 >>> True & False # and False >>> True | False # or True >>> True ^ True # xor False >>> ~T.. 2021. 4. 15.
[알고리즘 algorithm] 이진 검색 Binary Search 정의와 사용 예제 이진 검색: 정렬된 배열에서 타겟을 찾는 검색 알고리즘. 시간복잡도가 O(logN)로 1억개의 데이터에서도 단 27번 안에 원하는 데이터를 찾아낼 수 있는 정말 마법같은 검색 알고리즘이다. 이진탐색트리와 이진검색은 유사한 점이 많은데 이진탐색트리(BST)가 정렬된 구조를 저장하고 탐색하는 자료구조라면, 이진검색은 정렬된 배열에서 값을 찾아내는 알고리즘 자체를 지칭한다. 이진 검색 기본 문제: leetcode.com/problems/binary-search/ Binary Search - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepare.. 2021. 4. 15.
[리트코드 leetcode] 147. Insertion Sort List leetcode.com/problems/insertion-sort-list/ Insertion Sort List - 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 풀긴 하였지만 소요 시간이 매우 길다.. # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution:.. 2021. 4. 14.
반응형