TreeviewCopyright © aleen42 all right reserved, powered by aleen42

1108. IP 地址无效化

https://leetcode-cn.com/problems/defanging-an-ip-address/

Java

/*
 * @Author: Goog Tech
 * @Date: 2020-08-09 07:42:42
 * @LastEditTime: 2020-08-09 07:43:54
 * @Description: https://leetcode-cn.com/problems/defanging-an-ip-address/
 * @FilePath: \leetcode-googtech\#1108. Defanging an IP Address\Solution.java
 */

class Solution {
    public String defangIPaddr(String address) {
        StringBuffer sb = new StringBuffer();
        char[] chars = address.toCharArray();
        for(char c : chars) {
            sb = c == '.' ? sb.append("[.]") : sb.append(c);
        }
        return sb.toString();
    }
}

Python

'''
Author: Goog Tech
Date: 2020-08-09 07:42:47
LastEditTime: 2020-08-09 07:43:15
Description: https://leetcode-cn.com/problems/defanging-an-ip-address/
FilePath: \leetcode-googtech\#1108. Defanging an IP Address\Solution.py
'''

class Solution(object):
    def defangIPaddr(self, address):
        """
        :type address: str
        :rtype: str
        """
        return address.replace('.', '[.]')
Copyright © GoogTech 2021 all right reserved,powered by GitbookLast update time : 2021-09-15 01:55:05

results matching ""

    No results matching ""