ARTS-004

作者: 玖柒叁 | 来源:发表于2019-07-08 09:47 被阅读0次

    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移出来后,只要移动到红框内即可以移动回去


    示例

    Share


    相关文章

      网友评论

        本文标题:ARTS-004

        本文链接:https://www.haomeiwen.com/subject/rxqbcctx.html