leetcode 8

[릿코드/LeetCode] 412. Fizz Buzz (파이썬3/Python3)

문제 https://leetcode.com/problems/fizz-buzz/ Fizz Buzz - 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 생각 우선 리스트를 증가하는 숫자로 채워놓고 Fizz와 Buzz들어갈 부분만 바꿔주면 될 듯? 나는 그냥 for문 돌려서 조건 맞으면 값 바꿔줘야겠다. - 그냥 바로 for문 돌리면서 append해도 굿! 코드 class Solution: def fizzBuzz(self, n: int) -> List[str]: R =..

문제/릿코드 2021.07.18

[릿코드/LeetCode] 169. Majority Element (파이썬3/Python3)

문제 https://leetcode.com/problems/majority-element/ Majority Element - 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 생각 리스트를 set으로 한 번 감싸고 최대 개수를 가지는 친구 찾기! 이제 그 친구가 n/2 이상이면 ㄱㄱ 코드 class Solution: def majorityElement(self, nums: List[int]) -> int: n = set(nums) max_n = 0 max_c = 0..

문제/릿코드 2021.07.18

[릿코드/LeetCode] 206. Reverse Linked List (파이썬3/Python3)

문제 https://leetcode.com/problems/reverse-linked-list/ Reverse Linked 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 생각 우리가 얻을 수 있는 값을 순서대로 작성하면, 1, 2, 3, 4, 5, None. 이 순서로 값이 들어올 것이다. 그렇다면 이를 활용하여 1, 2-1, 3-2-1, 4-3-2-1, 5-4-3-2-1. 이렇게 만들면 될 것 같다! 출력은 이제 None이 들어오게되면 출력하면 될..

문제/릿코드 2021.07.18

[릿코드/LeetCode] 342. Power of Four (파이썬3/Python3)

문제 https://leetcode.com/problems/power-of-four/ Power of Four - 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이하는 무조건 false이고 1은 무조건 true 4로 열심히 나누다가 마지막에 나머지가 2또는 3이면 false, 1이면 true - 4로 더이상 나눌 수 없을 때까지 나눈다. (나머지가 4미만이면 멈춤) 나머지가 1이면 true 아니면 false - 16을 넣었을 때 나머지 바로 4미만임..

문제/릿코드 2021.07.11

[릿코드/LeetCode] 551. Student Attendance Record I (파이썬3/Python3)

문제 https://leetcode.com/problems/student-attendance-record-i/ Student Attendance Record I - 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 생각 결석은 2번 이상하면 안 되고, 지각는 3일 연속으로 하면 안 되는 듯? 결석은 그냥 += 1하고 지각은 다른 거 나오면 리셋시키고 지각나오면 += 1하면 될 듯? - 코드 class Solution: def checkRecord(self, s: s..

문제/릿코드 2021.07.11

[릿코드/LeetCode] 14. Longest Common Prefix (파이썬3/Python3)

문제 https://leetcode.com/problems/longest-common-prefix/ Longest Common Prefix - 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 생각 prefix면 앞에서부터 비교해야하는 건가? 우선 list안에 있는 가장 짧은 단어를 찾고 이를 기준으로 앞에서부터 비교? - 파이썬 문자열 길이를 기준으로 정렬하려면, sort 메소드에서 key=len을 하면 된다고 함! 코드 class Solution: def lon..

문제/릿코드 2021.07.10

[릿코드/LeetCode] 66. Plus One (파이썬3/Python3)

문제 https://leetcode.com/problems/plus-one/ Plus One - 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 생각 숫자(리스트)를 count up을 한 번 하는 것이 목표 마지막 자리를 +1하면 되지만 carry가 발생하는 경우를 생각해줘야함. 가장 마지막 원소를 +1하고 carry가 발생하면 앞쪽으로 넘겨주기? 코드 class Solution: def plusOne(self, digits: List[int]) -> List[i..

문제/릿코드 2021.07.08

[릿코드/LeetCode] 455. Assign Cookies (파이썬3/Python3)

문제 https://leetcode.com/problems/assign-cookies/ Assign Cookies - 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 생각 으음 그러면 애들이 원하는 사이즈와 쿠키의 크기가 정렬되어있는건가? 그렇진 않겠지? 애들이 원하는 사이즈보다 쿠키가 같거나 크면 output 수를 1 더해주기. 이미 만족한 쿠키면 다음 쿠키부터. 쿠키를 기준으로 진행해야됨! 쿠키를 분배해주는 것이니까. 코드 class Solution: def ..

문제/릿코드 2021.07.07