코딩테스트/LeetCode

https://leetcode.com/problems/count-primes/ Step1. n개의 True로 구성된 is_prime 리스트 생성Step2. 0과 1에 대해 소수가 아니므로 False로 미리 처리Step3. 2부터 루트 n까지 반복하면서Step4. 그 수의 배수들을 False 처리Step5. is_prime 리스트에서 최종적으로 True의 개수만 세기 import mathclass Solution(object): def countPrimes(self, n): """ :type n: int :rtype: int """ if n == 0 or n == 1: return 0 is_prime = [..

https://leetcode.com/problems/first-unique-character-in-a-string?source=submission-ac SolutionStep 1. 주어진 String에서 하나씩 돌면서 char 확인하기Step 2. i번재 char이 이전에 나왔는지, 이후에 또 나오는지를 체크함Step 3. 반복되지 않을 경우, 바로 break하고 answer return Step 4. 다 확인했는데도 해당하는 경우 없으면 -1 반환 Codeclass Solution(object): def firstUniqChar(self, s): char_list = [] for i in range(len(s)): char = s[i] ..