GeezerVison is showing github.com — 1108_Defanging_an_IP_Address · zhimintu/leetcode@f1e724a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: README.md +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -218,6 +218,7 @@ Also, there are open source implementations for basic data structs and algorithm | 218 | 218 | | 973 | [K Closest Points to Origin](https://leetcode.com/problems/k-closest-points-to-origin/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/973_K_Closest_Points_to_Origin.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/973_K_Closest_Points_to_Origin.java) | 1. Sort and get 0-K, O(nlogn) and O(1)<br>2. Min Heap, O(nlogk) and O(k) | | 219 | 219 | | 1064 | [Fixed Point](https://leetcode.com/problems/fixed-point/) ♥ | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1064_Fixed_Point.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1064_Fixed_Point.java) | 1. Go through index and value, until find solution encounter index < value, O(n) and O(1)<br>2. Binary search, O(logn) and O(1) | | 220 | 220 | | 1089 | [Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1089_Duplicate_Zeros.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1089_Duplicate_Zeros.java) | 2 Pass, store last position and final move steps, O(n) and O(1) | | | 221 | +| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1108_Defanging_an_IP_Address.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1108_Defanging_an_IP_Address.java) | String manipulate (split, replace and join), O(n) and O(n) | | 221 | 222 | | 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1260_Shift_2D_Grid.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1260_Shift_2D_Grid.java) | Final position of each element can be computed according to k, m and n, e.g., k == mn, then don't move, O(mn) and O(mn) | | 222 | 223 | | 1337 | [The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1337_The_K_Weakest_Rows_in_a_Matrix.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1337_The_K_Weakest_Rows_in_a_Matrix.java) | Check by row, from left to right, until encount first zero, O(mn) and O(1) | | 223 | 224 | | 1365 | [How Many Numbers Are Smaller Than the Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.java) | 1. Sort and get position in sorted nums, O(nlogn) and O(n)<br>2. Fill count into 0-100, O(n) and O(1) | | |
Collapse file Copy file name to clipboard +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +class Solution { | | 2 | + public String defangIPaddr(String address) { | | 3 | + // replace | | 4 | + return address.replace(".", "[.]"); | | 5 | + } | | 6 | + /* public String defangIPaddr(String address) { | | 7 | + // split and join | | 8 | + return String.join("[.]", address.split("\\.")); | | 9 | + } */ | | 10 | + /* public String defangIPaddr(String address) { | | 11 | + // replace | | 12 | + return address.replaceAll("\\.", "[.]"); | | 13 | + } */ | | 14 | + /* public String defangIPaddr(String address) { | | 15 | + // new string | | 16 | + StringBuilder sb = new StringBuilder(); | | 17 | + for (char c : address.toCharArray()) { | | 18 | + sb.append(c == '.' ? "[.]" : c); | | 19 | + } | | 20 | + return sb.toString(); | | 21 | + } */ | | 22 | +} |
Collapse file Copy file name to clipboard +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +class Solution: | | 2 | + def defangIPaddr(self, address: str) -> str: | | 3 | + # replace | | 4 | + return address.replace('.', '[.]') | | 5 | + # def defangIPaddr(self, address: str) -> str: | | 6 | + # # split and join | | 7 | + # return '[.]'.join(address.split('.')) | | 8 | + # def defangIPaddr(self, address: str) -> str: | | 9 | + # # replace | | 10 | + # return re.sub('\.', '[.]', address) | | 11 | + # def defangIPaddr(self, address: str) -> str: | | 12 | + # return ''.join('[.]' if c == '.' else c for c in address) |
|