ARTS-004

Algorithm


1108. Defanging an IP Address

public String defangIPaddr(String address) {
        StringBuilder sb = new StringBuilder();
        char[] ipv4 = address.toCharArray();
        for (int i = 0; i < ipv4.length; ++i) {
            if (ipv4[i] != '.') {
                sb.append(ipv4[i]);
                continue;
            }
            sb.append('[');
            sb.append('.');
            sb.append(']');
        }
        return sb.toString();
    }

1109. Corporate Flight Bookings

public int[] corpFlightBookings(int[][] bookings, int n) {
        int[] result = new int[n];
        for (int i = 0; i < bookings.length; ++i) {
            for (int j = bookings[i][0]; j <= bookings[i][1]; ++j) {
                int num =result[j] + bookings[i][2];
            }
        }
        return result;
    }

参考:C++ O(n)

int[] result = new int[n];
        for (int i = 0; i < bookings.length; ++i) {
            result[bookings[i][0] - 1] += bookings[i][2];
            //如果不是所有航班都被预定了,那么在j航班之后的就要排除掉
            if (bookings[i][1] < n) {
                result[bookings[i][1]] -= bookings[i][2];
            }
        }
        for (int i = 1; i < n; ++i) {
            result[i] += result[i-1];
        }
        return result;

Review


Tip


不小心把idea中debug窗口的console移出来后,只要移动到红框内即可以移动回去


ARTS-004_第1张图片
示例

Share


你可能感兴趣的:(ARTS-004)