Advertisement

网易雷火2023年春招笔试题:LeetCode相关题目

阅读量:

网易雷火2023年的人工智能研究员(自然语言处理领域)参与了笔试考试:其中两道算法题目源自LeetCode平台(LeetCode),具体为第440号和第845号题目。

LeetCode 386:

再做440之前,可以先做做386;可以算是440的基础题。

题目描述:

Given an integer n, return 1 - n in lexicographical order.

For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].

I suggest optimizing your algorithm to reduce its computational resources by lowering the time and space complexity. The input could reach up to 5 million elements.

题解:

题意与440大致相同;给定一个整数n,请返回其对应的有序排列数组。从提供的样例中推断出如何定义字典序:

  1. 一个数x,如果x*10 < n, 那么x后就是x*10
  2. 如果x*10 >= n, 那么x后接的就是x+1,这里需要注意的需要

全部评论 (0)

还没有任何评论哟~