Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 633 Bytes

1108.ip-地址无效化.md

File metadata and controls

32 lines (26 loc) · 633 Bytes

1108.ip-地址无效化

/*
 * @lc app=leetcode.cn id=1108 lang=typescript
 *
 * [1108] IP 地址无效化
 */

// @lc code=start
function defangIPaddr(address: string): string {}
// @lc code=end

解法 1: 替换字符串

function defangIPaddr(address: string): string {
  return address.replaceAll('.', '[.]')
}

Case

test.each([
  { input: { address: '1.1.1.1' }, output: '1[.]1[.]1[.]1' },
  { input: { address: '255.100.50.0' }, output: '255[.]100[.]50[.]0' },
])('input: address = $input.address', ({ input: { address }, output }) => {
  expect(defangIPaddr(address)).toEqual(output)
})