注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
Question 1:
You are given a singly linked list of integers. Your task is to modify the list so that: You keep only the first occurrence of each value. You remove any node whose value has already appeared earlier in the list. You then return the head of the updated linked list. . 1point 3 acres
Note: A LinkedListNode has two attributes: data, an integer, and next, a reference to the next item in the list or the language equivalent of null at the tail.
Example 1: In the following list, the value 3 appears as a duplicate initially: [3] -> [4] -> [3] -> [6]. Redundant nodes are labeled 3. After calling condense, the redundant node is removed: [3] -> [4] -> [6]. Example 2: List values in order are 3, 4, 3, 2, 6, 1, 2, 6.
Question 2: . 1point3acres
Determine the maximum length of a subsequence from one string that is also a substring of another string. A subsequence of a string is created by removing zero or more characters from it, while a substring consists of consecutive characters from the string. Given two strings x and y, determine the length of the longest subsequence of x that is also a substring of y. ..
Example: x = abcd, y = abdc. The subsequences of abcd are a, b, c, d, ab, ac, ad, bc, bd, cd, abc, abd, acd, bcd, and abcd. The substrings of abdc are a, b, d, c, ab, bd, dc, abd, bdc, and abdc. The longest subsequence of x that is also a substring of y is abd with length 3. Function
Sample Input 0: x = hackerranks, y = hackers. Sample Output 0: 7. Explanation: hackers is the longest subsequence of x that is also a substring of y.
|