【发布时间】:2020-07-09 04:07:38
【问题描述】:
我已经完成了编码,我的几个测试用例通过了,但是测试用例 2 和其他几个没有通过。当我在本地运行相同的代码时,我得到了想要的结果,但在 HackerRank 上,它显示运行时错误。
这是问题 - https://www.hackerrank.com/challenges/dynamic-array/problem
这是我的解决方案:-
public static List dynamicArray(int n, List> queries) {
List<List<int>> seqList = new List<List<int>>();
for (int j = 0; j < n ; j++)
{
seqList.Insert(j, new List<int>(n-1)) ;
}
List<int> seqList2 = new List<int>();
int lastAnswer = 0;
int index;
for (int i = 0; i < queries.Count ; i++)
{
index = ((queries[i][1] ^ lastAnswer) % n);
if (queries[i][0] == 1)
{
seqList[index].Add(Convert.ToInt32(queries[i][2]));
}
else
{
int value = queries[i][2] % seqList[index].Count ;
lastAnswer = seqList[index][value];
Console.WriteLine(lastAnswer);
seqList2.Add(lastAnswer);
}
}
【问题讨论】:
-
你确定这是你完整的 dynamicArray 函数,你是在某处返回 seqList 吗?
-
是的,我要返回 seqList2