快手java一面

  1. 问项目

  2. SQL28 每个供应商成本最低的产品 的变形题,求最高

  3. NC2 重排链表

sql语句和题都没写出来😥,现记录改后的答案:

  • sql部分:
SELECT
  vend_id,
  MIN(prod_price) AS cheapest_item
FROM
  Products
GROUP BY
  vend_id
ORDER BY
  cheapest_item ASC;
  • 重排链表
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public void reorderList(ListNode head) {
        if (head == null || head.next == null) return;

        // 找链表中点
        ListNode slow = head, fast = head;
        while (fast.next != null && fast.next.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }

        // 反转后半段链表
        ListNode secondList = slow.next;
        secondList = reverseList(secondList);
        slow.next = null;// 注意此处需要清空,使得head只有前半段,second只有后半段,否则后续连接会陷入死循环

        // 依次连接链表(插入节点)
        ListNode cur = head;
        while (secondList != null && cur != null) {
            // 记录分别的next节点防丢失
            ListNode firstListNext = cur.next;
            ListNode secondListNext = secondList.next;

            // 向cur插入secondList
            cur.next = secondList;
            secondList.next = firstListNext;

            // 重置cur和secondList
            cur = firstListNext;
            secondList = secondListNext;
        }
    }

    public ListNode reverseList(ListNode head) {
        if (head == null) return null;

        ListNode pre = null, cur = head, con = head.next;
        while (con != null) {
            cur.next = pre;
            pre = cur;
            cur = con;
            con = cur.next;
        }
        cur.next = pre;
        return cur;
    }
}
#面试复盘##春招##快手#
全部评论
我貌似也在牛客上看到过类似的题
点赞 回复 分享
发布于 2022-05-13 12:58
快手现在还有春招面试呀 😂
点赞 回复 分享
发布于 2022-05-13 14:23

相关推荐

Noob1024:一笔传三代,人走笔还在
点赞 评论 收藏
分享
3 6 评论
分享
牛客网
牛客企业服务