반응형
문제
Defanging an IP Address - LeetCode
문제 해결 방법
- 입력받은 ip address에서 .을 [.]으로 바꾸는 문제입니다.
- 스트링의 replace 메서드를 알고 있으면 쉽게 바꿀수 있습니다. replace메서드를 알고 있냐고 묻는 문제 입니다.
Github Link
https://github.com/eunhanlee/LeetCode_1108_DefanginganIPAddress_Solution.git
replace 시간복잡도: O(n), 공간복잡도: O(1)
class Solution {
/**
* 주어진 IP 주소에서 마침표를 지정된 대체 문자열로 대체하여 수정합니다.
*
* @param address 주소를 수정할 IP 주소
* @return 수정된 IP 주소
*/
public String defangIPaddr(String address) {
return address.replace(".","[.]");
}
}
참고
반응형
'old > Algorithm Solving' 카테고리의 다른 글
LeetCode 238. Product of Array Except Self 자바 문제 풀이 (0) | 2023.06.28 |
---|---|
LeetCode 215. Kth Largest Element in an Array 자바 문제 풀이 (0) | 2023.06.22 |
LeetCode 2011. Final Value of Variable After Performing Operations 자바 문제 풀이 (0) | 2023.06.18 |
LeetCode 169. Majority Element 문제 풀이 (0) | 2023.05.18 |
136. Single Number 문제의 자바 해결 방법: 효율적인 알고리즘 (0) | 2023.05.09 |