{"id":5284,"date":"2019-07-11T09:09:24","date_gmt":"2019-07-11T16:09:24","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=5284"},"modified":"2019-09-29T21:47:26","modified_gmt":"2019-09-30T04:47:26","slug":"leetcode-1108-defanging-an-ip-address","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/string\/leetcode-1108-defanging-an-ip-address\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 1108. Defanging an IP Address"},"content":{"rendered":"\n<p>Given a valid (IPv4) IP&nbsp;<code>address<\/code>, return a defanged version of that IP address.<\/p>\n\n\n\n<p>A&nbsp;<em>defanged&nbsp;IP address<\/em>&nbsp;replaces every period&nbsp;<code>\".\"<\/code>&nbsp;with&nbsp;<code>\"[.]\"<\/code>.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted; crayon:false\"><strong>Input:<\/strong> address = \"1.1.1.1\"\n<strong>Output:<\/strong> \"1[.]1[.]1[.]1\"\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted; crayon:false\"><strong>Input:<\/strong> address = \"255.100.50.0\"\n<strong>Output:<\/strong> \"255[.]100[.]50[.]0\"\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The given&nbsp;<code>address<\/code>&nbsp;is a valid IPv4 address.<\/li><\/ul>\n\n\n<p><script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br>\n<ins class=\"adsbygoogle\" style=\"display:block\" data-ad-format=\"fluid\" data-ad-layout-key=\"-fb+5w+4e-db+86\" data-ad-client=\"ca-pub-2404451723245401\" data-ad-slot=\"2162692788\"><\/ins><br>\n<script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><\/p>\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: String<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(n)<br>Space complexity: O(n)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">class Solution {\npublic:\n  string defangIPaddr(string address) {\n    string output;\n    for (const char c : address) {\n      if (c == '.') output += \"[.]\";\n      else output += c;\n    }\n    return output;\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Given a valid (IPv4) IP&nbsp;address, return a defanged version of that IP address. A&nbsp;defanged&nbsp;IP address&nbsp;replaces every period&nbsp;&#8220;.&#8221;&nbsp;with&nbsp;&#8220;[.]&#8221;. Example 1: Input: address = &#8220;1.1.1.1&#8221; Output: &#8220;1[.]1[.]1[.]1&#8243;&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[222,4],"class_list":["post-5284","post","type-post","status-publish","format-standard","hentry","category-string","tag-easy","tag-string","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=5284"}],"version-history":[{"count":3,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5284\/revisions"}],"predecessor-version":[{"id":5645,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5284\/revisions\/5645"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=5284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=5284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=5284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}