@TOC
# 一、Fizz Buzz ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/16fb1e1df9194404b405bd0f0d524e94.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAV1NLSDA5Mjk=,size_20,color_FFFFFF,t_70,g_se,x_16) ```java public List fizzBuzz(int n) { List list = new ArrayList<>(n); for (int i = 1; i <= n ; i++) { boolean b1 = i%3==0; boolean b2 = i%5==0; if(b1&&b2){ list.add("FizzBuzz"); }else if(b1){ list.add("Fizz"); }else if(b2){ list.add("Buzz"); }else{ list.add(""+i); } } return list; } ```
# 二、计数质数 ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/b7f9a36f729240dd8905c74644f8aab3.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAV1NLSDA5Mjk=,size_20,color_FFFFFF,t_70,g_se,x_16) ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/c6216620579a4e66befd3770985778da.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAV1NLSDA5Mjk=,size_20,color_FFFFFF,t_70,g_se,x_16) ```java public int countPrimes(int n) { boolean[] arr = new boolean[n]; int cnt = 0; for(int i = 2; i < n; i++) { if(arr[i]) continue; cnt++; for(int j = i; j < n; j+=i) { arr[j] = true; } } return cnt; } ```
# 三、3的幂 ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/17d5339cfa5041c5a50683107cdb7f99.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAV1NLSDA5Mjk=,size_20,color_FFFFFF,t_70,g_se,x_16) ```java public boolean isPowerOfThree(int n) { if (n > 1){ while (n % 3 == 0){ n /= 3; } } return n == 1; } ```
# 四、罗马数字转整数 ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/f257427cf08941379cdabd0290184183.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAV1NLSDA5Mjk=,size_20,color_FFFFFF,t_70,g_se,x_16) ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/79c6157febac4672ba538720c75e1c95.png) ```java public int romanToInt(String s) { Map map = new HashMap<>(); map.put("I",1); map.put("IV",4); map.put("V",5); map.put("IX",9); map.put("X",10); map.put("XL",40); map.put("L",50); map.put("XC",90); map.put("C",100); map.put("CD",400); map.put("D",500); map.put("CM",900); map.put("M",1000); if(map.containsKey(s)){ return map.get(s); }else{ StringBuilder sb = new StringBuilder(); int num = 0; char[] chars = s.toCharArray(); for (int i = 0; i < chars.length; i++) { if(!map.containsKey(sb.toString()+chars[i])){ if(sb.length()>0){ num += map.get(sb.toString()); sb = new StringBuilder(); i--; } }else{ sb.append(chars[i]); } } if(sb.length()>0){ num += map.get(sb.toString()); } return num; } } ```