You get a shopping list items, an array of strings, and a word item. Add item at the end only when it isn't in the list yet. Return the list.
When item is already there, the list stays as it is. The list may start empty.
Example 1:
Input: items = ["milk", "eggs"], item = "bread" Output: ["milk", "eggs", "bread"] Explanation: The word "bread" is not in the list yet. It goes at the end.
Example 2:
Input: items = ["milk", "eggs"], item = "milk" Output: ["milk", "eggs"] Explanation: The word "milk" is already there. Nothing is added.
Example 3:
Input: items = [], item = "apples" Output: ["apples"] Explanation: The list is empty, so "apples" is new. It becomes the only item.
Constraints:
itemshas 0 to 9 words: it may be empty.itemand every word initemsare made of lowercase English letters.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
