Skip to content

Commit 5f46253

Browse files
committed
190706 contest
1 parent e640b17 commit 5f46253

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

1108_Defanging an IP Address.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public String defangIPaddr(String address) {
3+
String[] ip = address.split("\\.");
4+
String res = "";
5+
for (String s : ip) {
6+
res += s + "[.]";
7+
}
8+
res = res.substring(0, res.length() - 3);
9+
return res;
10+
}
11+
}

1109_Corporate Flight Bookings.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// O(n)/O(n)
2+
class Solution {
3+
public int[] corpFlightBookings(int[][] bookings, int n) {
4+
// Arrays.sort(bookings, (a, b) -> a[0] - b[0]);
5+
int[] change = new int[n + 1], res = new int[n];
6+
for (int i = 0; i < bookings.length; i++) {
7+
change[bookings[i][0] - 1] += bookings[i][2];
8+
change[bookings[i][1]] -= bookings[i][2];
9+
}
10+
res[0] = change[0];
11+
for (int i = 1; i < n; i++)
12+
res[i] = res[i - 1] + change[i];
13+
return res;
14+
}
15+
}

0 commit comments

Comments
 (0)