개발공부/algorithm

개발공부/algorithm

[leetcode][python] 278. First Bad Version - Binary Search

Problem Leetcode 278: First Bad version Level: Easy Link First Bad Version - 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 My Code 기본적인 이진탐색 문제다. 이진 탐색을 진행해주며 가장 먼저 발생하는 bad version을 체크해준다. # The isBadVersion API is already defined for you. # @param version, an integer # @return ..

개발공부/algorithm

[Leetcode][python] 58: Length of Last Word

문제 Leetcode 58: Length of Last word Level: Easy Link Length of Last Word - 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 나의 풀이 쉬워보이지만 반례가 많아서 세심한 디버깅이 필요한 문제다. 받은 스트링 값을 " "로 split해주고, 뒤에서부터 탐색하며 길이가 0이 아닌 element를 리턴해준다. class Solution: def lengthOfLastWord(self, s: str) -> int:..

개발공부/algorithm

[백준][python] 17626 - Four squares

문제 백준 17626: Four Squares Silver V 문제링크 17626번: Four Squares 라그랑주는 1770년에 모든 자연수는 넷 혹은 그 이하의 제곱수의 합으로 표현할 수 있다고 증명하였다. 어떤 자연수는 복수의 방법으로 표현된다. 예를 들면, 26은 52과 12의 합이다; 또한 42 + 32 + 1 www.acmicpc.net N = int(input()) min_sum = 4 for a in range(int(N**0.5), int((N//4)**0.5), -1): if a*a == N: min_sum = 1 break else: temp = N - a*a for b in range(int(temp**0.5), int((temp//3)**0.5), -1): if a*a + b*b..

so.py
'개발공부/algorithm' 카테고리의 글 목록 (3 Page)