프로필사진

Go, Vantage point

가까운 곳을 걷지 않고 서는 먼 곳을 갈 수 없다.


Github | https://github.com/overnew/

Blog | https://everenew.tistory.com/





티스토리 뷰

반응형

문제

 

https://leetcode.com/problems/split-array-into-maximum-number-of-subarrays/description/

 

LeetCode - The World's Leading Online Programming Learning Platform

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

 

 

 

 

 

풀이

 

난이도: Medium 

 

 

SubArr는 연속이어야 했기때문에 쉬운 문제였다.

A subarray is a contiguous part of an array.

 

SubArr들의 Score Sum이 최소가 될려면, 분리할 SubArr는 반드시 score 0을 만들어야 한다.

분리없이 Score가 0이였는데, 분리된 subArr에서 Score가 1이라도 만들어진다면, 0 +1로 최소 sum을 만족하지 못한다.

 

따라서 연속된 배열을 AND 연산을 해보면서, 0이된다면 subArr(start~end)로 분리시킬때 subArr를 최대한 만들 수 있다.

만약 남겨진 배열로는 0을 만들지 못하면 0을 만든 이전 subArr와 합치면 0이 만들어진다.

 

 

 

 

 

코드

 

 

반응형
댓글
반응형
인기글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함