Notice
Recent Posts
Recent Comments
Link
목록array (2)
오늘도 개발
1. Find Numbers with Even Number of Digits
문제 nums 배열에서 자릿수가 짝수인 요소의 개수를 구하시오. Input: nums = [12,345,2,6,7896] Output: 2 내가 해결한 방식 def findNumbers(self, nums: List[int]) -> int: return sum([len(str(num)) % 2 == 0 for num in nums])
자료구조 & 알고리즘/Leetcode
2022. 5. 6. 13:14
0. Max Consecutive Ones
문제 이진수로 이루어진 nums 배열을 인수로 받는다. 이 중 가장 긴 1의 반복 횟수를 구하시오. Input: nums = [1,1,0,1,1,1] Output: 3 내가 생각한 방식 최대 반복된 횟수를 알 수 있도록 max 변수 만들어서 비교, 반복된 횟수가 가장 많은 경우 max에 저장 // c++ class Solution { public: int findMaxConsecutiveOnes(vector& nums) { int count = 0; int max = 0; for (int n : nums){ if (n==1){ count++; if (max < count) max = count; } else count = 0; } return max; } }; # python def findMaxCons..
자료구조 & 알고리즘/Leetcode
2022. 5. 6. 12:35