#97. 查找最后一个特定元素并截取数组

    ID: 97 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-2gesp3一维数组循环结构

查找最后一个特定元素并截取数组

Elements After Last Four

Background

Congcong is currently learning about array operations. He encountered an interesting problem that requires extracting specific elements from an integer array.

Problem Description

Given a non-empty array of integers, return a new array containing the elements from the original array that come after the last 44 in the original array. The original array will contain at least one 44. Note that it is valid in Java to create an array of length 00.

Input Format

Input is given from standard input in the following format.

An array of integers, with elements separated by spaces and enclosed in square brackets []. For example: [2 4 1 2]

Output Format

Output is printed to standard output in the following format.

A new array of integers containing all elements after the last 44 in the original array. Elements are separated by a comma and space , and enclosed in square brackets []. If 44 is the last element, an empty array [] should be returned.

Sample

[2 4 1 2]
[1, 2]
[4 1 4 2]
[2]
[4 4 1 2 3]
[1, 2, 3]

Sample Explanation

Sample 11: After the last 44 in the array, the elements are 11 and 22. Sample 22: After the last 44 in the array, the element is 22. Sample 33: After the last 44 in the array, the elements are 11, 22, and 33.

Constraints

Time limit: 11 second, Memory limit: 10241024 KiB for each test case.