注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
白嫖,四道题,70min
1. 一道很简单的数组遍历,略
2.A cyclic shift is the operation of rearranging the digits in a number (in decimal format) by moving some digits at the end of the number to before the beginning of the number, while shifting all other digits to the next position. Given two integers of the same length a and b, a would be a cyclic pair of b if it's possible for a to become equal to b after performing cyclic shifts on a - moving 0 or more ending digits to the beginning while shifting all other digits to the next position in the same order.
Given an array of positive integers a, your task is to count the number of cyclic pairs i and j (where 0 ≤ i < j < a.length), such that a[i] and a[j] have the same number of digits and a[i] is equal to a cyclic shift of a[j].
Example
For a = [13, 5604, 31, 2, 13, 4560, 546, 654, 456], the output should be solution(a) = 5.
There are 5 cyclicpected to provide the most optimal solution, but a solution with time complexity not worse than O(numRows · numColumns · laserCoordinates.length) will fit within the execution time limit.
Example
For numRows = 8, numColumns = 8, curRow = 5, curColumn = 3, and laserCoordinates = [[1, 6], [2, 8]], the output should be solution(numRows, numColumns, curRow, curColumn, laserCoordinates) = 3.
Explanation:
Given the 8 × 8 board, there are two lasers with centers at cells (1, 6) and (2, 8). The animation below shows that the longest safe path for the robot is 3.
求加米!! |