Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions leetcode2/1easy/이준열/1437.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution {
public:
bool kLengthApart(vector<int>& 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;
}
};
27 changes: 27 additions & 0 deletions leetcode2/2medium/이준열/3096.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution {
public:
int minimumLevels(vector<int>& possible) {
vector<int> 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
};