shoppe虾皮研发岗秋招第四批
一、15道选择题做的一塌糊涂
主要包括kafka、进程通信、TCP、概率题、redis等
二、编程题
1、找出没出现的最小正整数
2、判断链表是否回文
3、字符串数组,每个元素包含“姓名,交易额,时间、城市”,要求挑出交易额大于1000和姓名相同城市不同并且交易额差<=60的元素
/* 第一题 */ public class Solution { /** * * @param nums int整型一维数组 入参数组 * @return int整型 */ public int firstMissingPositive (int[] nums) { // write code here Arrays.sort(nums); int i =0; while(i<nums.length){ if (nums[i]>0) break; else i++; } if (i==nums.length||nums[i]!=1) return 1; int now = 1; for(;i<nums.length;i++){ if (nums[i]==now){ now++; }else{ return now; } } return now; } } /* 第二题 */ /* * public class ListNode { * int val; * ListNode next = null; * } */ public class Solution { /** * * @param pHead ListNode类 * @return bool布尔型 */ public boolean isPalindrome (ListNode pHead) { // write code here //先截断 ListNode slow = pHead; ListNode fast = pHead; while(fast!=null&&fast.next!=null){ slow = slow.next; fast = fast.next.next; } //再反转 ListNode res ; if (fast==null){ res = reverse(slow); }else{ res = reverse(slow.next); } //最后判断 while(res!=null){ if (res.val!=pHead.val) return false; res = res.next; } return true; } public ListNode reverse(ListNode head){ ListNode p = null; ListNode q = head; while(q!=null){ ListNode flag = q.next; q.next = p; p = q; q = flag; } return p; } } /* 第三题 */ public class Solution { /** * * @param vTransaction string字符串一维数组 * @return string字符串一维数组 */ public String[] invalidTransaction (String[] vTransaction) { // write code here String[] res = new String[vTransaction.length]; int count = 0; HashSet<String> data = new HashSet<>(); List<List<String>> list= new ArrayList<>(); for(int i=0;i<vTransaction.length;i++){ String[] now = vTransaction[i].split(","); int money = Integer.valueOf(now[2]); if (money>1000){ res[count] = vTransaction[i]; count++; continue; } if (data.contains(now[0])){ for(int j=0;j<list.size();){ if (list.get(j).get(0).equals(now[0])){ int nowTime = Integer.valueOf(now[1]); String[] in = list.get(j).get(1).split(","); int inTime = Integer.valueOf(in[1]); String insite = in[3]; if (!now[3].equals(insite)&&Math.abs(inTime-nowTime)<=60){ res[count] = list.get(j).get(1); count++; res[count] = vTransaction[i]; count++; list.remove(j); } }else{ j++; } } }else{ List<String> flag = new ArrayList<>(); flag.add(now[0]); flag.add(vTransaction[i]); list.add(flag); data.add(now[0]); } } return Arrays.copyOf(res,count); } }
全部评论
(1) 回帖