第一题:1108. IP 地址无效化
代码实现
class Solution { public String defangIPaddr(String address) { StringBuffer stringBuffer=new StringBuffer(); for(int i=0;i<address.length();i++){ if(address.charAt(i) == '.'){ stringBuffer.append("[.]"); }else{ stringBuffer.append(address.charAt(i)); } } return new String(stringBuffer); } }
代码实现
class Solution{ public String replaceSpace(String s){ StringBuilder sb=new StringBuilder(); for(Character c:s.toCharArray()){ if(c==' '){ sb.append("%20"); } else{ sb.append(c); } } return sb.toString(); } }
代码实现
class Solution { public int[] smallerNumbersThanCurrent(int[] nums) { int len = nums.length; int[] res = new int[len]; for (int i = 0; i < len; i++) { for (int j = 0; j < len; j++) { if (i == j) continue; if (nums[i] > nums[j]) res[i]++; } } return res; } }
代码实现