-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
22 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Solution { | ||
public int solution(int n, int[] stations, int w) { | ||
int answer = 0; | ||
|
||
int apt = 1; | ||
for(int i = 0; i < stations.length; i++) { | ||
int start = stations[i] - w; | ||
int end = stations[i] + w; | ||
if(apt < start) { | ||
answer += build(start-apt, w); | ||
} | ||
apt = end + 1; // 커버되지 않은 아파트 | ||
} | ||
if(apt <= n) { | ||
answer += build(n-apt+1, w); // n까지의 모든 아파트를 포함해야 하므로 + 1 | ||
} | ||
return answer; | ||
} | ||
static int build(int dist, int w) { | ||
return dist / (2 * w + 1) + (dist % (2 * w + 1) > 0 ? 1 : 0); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.