Skip to content

Feature/delf nov2 #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update line3
  • Loading branch information
Delf-Lee committed Nov 13, 2020
commit 5ce5c999a8b7576f26cc4fe1b69f562be2106f9d
86 changes: 86 additions & 0 deletions src/delf/etc/ln/Ln03.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package etc.ln;

import java.util.ArrayList;
import java.util.List;

/**
* @author delf
*/
public class Ln03 {
public static void main(String[] args) {
System.out.println(new Ln03().solution("1110111100001111101111110000011111", 3));
System.out.println(new Ln03().solution("001100", 5));

}

public int solution(String road, int n) {
List<Interval> list = new ArrayList<>();
char[] arr = road.toCharArray();
boolean isContinue = true;
int start = 0;
for (int i = 0; i < road.length(); i++) {
if (isContinue) {
if (i == road.length() - 1 || arr[i + 1] == '0') {
list.add(new Interval(start, i));
isContinue = false;
}
continue;
}
if (arr[i] == '1') {
start = i;
isContinue = true;
}
}

int max = 0;
int startInterval = 0;
do {
int sum = 0;
int empty = 0;
for (int i = startInterval; i < list.size() - 1; i++) {
Interval tmp = list.get(i);
sum += tmp.getLength();
if ((empty += tmp.getDiff(list.get(i + 1))) > n) {
break;
}
}
max = Math.max(sum + n, max);
} while (startInterval++ < list.size());

return max;
}

class Interval {
private int start;
private int end;
private int length;

public Interval(int start, int end) {
this.start = start;
this.end = end;
length = end - start + 1;
}

public boolean isLonger(Interval interval) {
return this.length > interval.length;
}


@Override
public String toString() {
return "Interval{" +
"start=" + start +
", end=" + end +
", length=" + length +
'}';
}

public int getLength() {
return length;
}

public int getDiff(Interval interval) {
return interval.start - this.end - 1;
}
}
}
10 changes: 5 additions & 5 deletions src/delf/etc/NV01.java → src/delf/etc/ln/Ln06.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package etc;
package etc.ln;

import java.util.*;

public class NV01 {
public class Ln06 {

public static void main(String[] args) throws CloneNotSupportedException {
System.out.println(Arrays.toString(new NV01().solution(
System.out.println(Arrays.toString(new Ln06().solution(
new String[]{"/", "/hello", "/hello/tmp", "/root", "/root/abcd", "/root/abcd/etc", "/root/abcd/hello"},
new String[]{"mkdir /root/tmp", "cp /hello /root/tmp", "rm /hello"}))
);

System.out.println(Arrays.toString(new NV01().solution(
System.out.println(Arrays.toString(new Ln06().solution(
new String[]{"/"},
new String[]{"mkdir /a", "mkdir /a/b", "mkdir /a/b/c", "cp /a/b /", "rm /a/b/c"}))
);

System.out.println(Arrays.toString(new NV01().solution(
System.out.println(Arrays.toString(new Ln06().solution(
new String[]{"/"},
new String[]{"mkdir /a", "mkdir /a/b", "mkdir /a/b/c", "cp /a/b /", "rm /a/b/c"}))
);
Expand Down