diff --git "a/leetcode2/1easy/\354\235\264\354\244\200\354\227\264/1437.cpp" "b/leetcode2/1easy/\354\235\264\354\244\200\354\227\264/1437.cpp" new file mode 100644 index 00000000..c6b84068 --- /dev/null +++ "b/leetcode2/1easy/\354\235\264\354\244\200\354\227\264/1437.cpp" @@ -0,0 +1,28 @@ +class Solution { + public: + bool kLengthApart(vector& nums, int k) { + int zeroCount = 0; + int oneIndex = -1; + for (int i = 0; i < nums.size(); i++) + { + if (nums[i] == 1) + { + if (oneIndex == -1) + { + oneIndex = 0; + } + else + { + if (zeroCount < k) + return false; + } + zeroCount = 0; + } + else if (nums[i] == 0) + { + zeroCount++; + } + } + return true; + } + }; \ No newline at end of file diff --git "a/leetcode2/2medium/\354\235\264\354\244\200\354\227\264/3096.cpp" "b/leetcode2/2medium/\354\235\264\354\244\200\354\227\264/3096.cpp" new file mode 100644 index 00000000..5b0059c9 --- /dev/null +++ "b/leetcode2/2medium/\354\235\264\354\244\200\354\227\264/3096.cpp" @@ -0,0 +1,27 @@ +class Solution { + public: + int minimumLevels(vector& possible) { + vector prefixSum(possible.size()); + prefixSum[0] = (possible[0] == 0) ? -1 : 1; + int totalSum; + + for (int i = 1; i < possible.size(); i++) + { + int point = (possible[i] == 0) ? -1 : 1; + prefixSum[i] = prefixSum[i-1] + point; + } + totalSum = prefixSum[possible.size()-1]; + + for (int j = 0; j < prefixSum.size()-1; j++) + { + if (prefixSum[j] > (totalSum - prefixSum[j])) + return j + 1; + } + return -1; + } + + // possible[i] == 0 -> always fail + // player clear +1 / fail -1 + // Alice plays first till K level + // Bob plays rest of the games + }; \ No newline at end of file