목록분류 전체보기 (40)
EPguy
문제 You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously. Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string. Return any permutation of s that satisfies this property. 두 개..
이진 탐색은 정렬된 배열에서만 사용할 수 있으며 검색 간격을 반복적으로 반으로 나누어 가면서 탐색하는 탐색 알고리즘 중 하나입니다. 동작방식 1. 배열의 중간 인덱스인 mid, 탐색할 배열의 맨 왼쪽 인덱스인 left, 맨 오른쪽인 right를 계산해야합니다. 2. 중간 인덱스는 (left + right) / 2 로 계산합니다, 이 때 정수가 돼야함으로 소수점은 버립니다. 3. 배열의 mid번째 요소와 탐색 할 숫자를 비교합니다. 4. 탐색할 숫자가 더 크면, left를 mid + 1 번째 인덱스로 바꿔줍니다. 5. 탐색할 숫자가 더 작으면, right를 mid - 1 번째 인덱스로 바꿔줍니다. 6. 탐색 범위를 초과하기 전까지 반복합니다. 7. left가 right보다 크면 탐색할 범위를 초과한 것이므..
문제 You are given an array nums consisting of positive integers. Return the total frequencies of elements in nums such that those elements all have the maximum frequency. The frequency of an element is the number of occurrences of that element in the array. 양의 정수로 이루어진 배열 nums가 주어집니다. 해당 배열의 원소들 중에서 가장 빈도수가 높은 원소들의 총 빈도수를 반환해야 합니다. 여기서 원소의 빈도수란 해당 원소가 배열에서 등장하는 횟수를 의미합니다. 풀이 1. Count Frequency an..
문제 Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node. singly linked list가 주어졌을 때 linked list의 가운데 노드를 반환하세요. 만약 두개의 중간 노드가 있을경우 두번째 노드를 반환하세요. 풀이 1. Counting element 알고리즘 Linked List의 노드 개수를 구한 다음, 가운데 인덱스의 Node를 찾는 방법입니다. class Solution(object): def middleNode(self, head): node = head size = 0 while(no..
문제 Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. 정수 배열 nums와 정수 target이 주어졌을 때, 두 개의 숫자를 더하면 target이 되는 인덱스들을 반환해야한다. 각 입력은 정확히 하나의 해결책을 가지며, 동일한 요소를 두 번 사용하지 않아야 합니다. 답변은 어떤..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/mCt6J/btsFuOsZkYh/Dt6IoZk7rDWWQKhHkimr91/img.gif)
import pygame pygame.init() WHITE = (255, 255, 255) WIDTH, HEIGHT = 500, 500 screen = pygame.display.set_mode((WIDTH, HEIGHT)) clock = pygame.time.Clock() GRAVITY = 0.7 PLAYER_RUN_SPEED = 2 PLAYER_JUMP_SPEED = 6 PLAYER_MASS = 0.7 class Character: def __init__(self, image, run_speed, jump_speed): self.original_image = image self.image = image self.rect = image.get_rect() self.movement = 0 self.di..