Topic 1

solution
class Solution { public int thirdMax(int[] nums) { Arrays.sort(nums);
if(nums.length<3){ return nums[nums.length-1]; } int p = 1; for(int i
=nums.length-2;i>=0;i--){ if(nums[i]==nums[i+1]){ }else{ ++p; if(p==3){ return
nums[i]; } } } return nums[nums.length-1]; } }
Topic 2

 

solution
class Solution { public List<String> fizzBuzz(int n) { ArrayList<String> list
=new ArrayList<String>(); for(int i = 1;i<=n;i++){ if(i%3==0&&i%5==0){
list.add("FizzBuzz"); }else if(i%3==0){ list.add("Fizz"); }else if(i%5==0){
list.add("Buzz"); }else{ list.add(""+i); } } return list; } }
Topic 3

solution
class Solution { public char findTheDifference(String s, String t) { int[] q =
new int[500]; for(int i = 0;i<s.length();i++){ q[s.charAt(i)] += 1; } for(int i
= 0;i<t.length();i++){ q[t.charAt(i)]-=1; if(q[t.charAt(i)]<0){ return
t.charAt(i); } } return t.charAt(0); } }
Topic 4

solution
class Solution { public int firstUniqChar(String s) { int[] w = new int[60];
for(int i=0;i<s.length();i++){ w[s.charAt(i)-'a']+=1; } char z = 'a'; for(int i
=0;i<w.length;i++){ if(w[i]==1){ z =(char)(i+'a'); break; } } for(int
i=0;i<s.length();i++){ if(w[s.charAt(i)-'a']==1){ return i; } } return -1; } }
Topic 5

solution
class Solution { public int findMaxConsecutiveOnes(int[] nums) { int maxCount
= 0, count = 0; int n = nums.length; for (int i = 0; i < n; i++) { if (nums[i]
== 1) { count++; } else { maxCount = Math.max(maxCount, count); count = 0; } }
maxCount = Math.max(maxCount, count); return maxCount; } }

Technology
©2019-2020 Toolsou All rights reserved,
【C++ Must see for entry 】C++ from 0 reach 1 Introductory programming axios Interceptor packaging and use Spring Boot Interview must ask : Automatic configuration principle VMware 16 install centos 7 Detailed tutorial C Language data structure - Sequence table delete duplicates V2.0.0 The 12th Blue Bridge Cup c++b Group personal problem solving On sending data from serial port single chip microcomputer to upper computer centos7 install RabbitMqjava Polymorphic array of opencv-python Fourier transform and inverse transform