力扣题目报内存溢出错误
在写力扣题目时,报<--- Last few GCs --->
359 ms: Mark-sweep (reduce) 133.2 (138.1) -> 82.7 (84.7) MB, 13.9 / 0.0 ms(+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 14 ms) (average mu = 0.770, current mu = 0.775) last resort G 372 ms: Mark-sweep (reduce) 82.7 (84.7) -> 82.7 (84.4) MB, 12.7 / 0.0 ms(average mu = 0.624, current mu = 0.001) last resort GC in old space requested
<--- JS stacktrace --->
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: 0xb00e10 node::Abort()
2: 0xa1823b node::FatalError(char const*, char const*)
3: 0xcee09e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool)
4: 0xcee417 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool)
5: 0xea65d5
6: 0xeb8a58 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment)
7: 0xe79b12 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment)
8: 0xe7443c v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray(int, v8::internal::AllocationType)
9: 0xe74515 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller(v8::internal::Handle<v8::internal::Map>, int, v8::internal::Handle<v8::internal::Oddball>, v8::internal::AllocationType)
10: 0x10221b2
11: 0x1022af6
12: 0x11e3783 v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*)
13: 0x15e7cf9
错误
题为力扣 121. 买卖股票的最佳时机
我的代码为:
/**
* @param {number[]} prices
* @return {number}
*/
var maxProfit = function(prices) {
let result=[]
if(prices.length<=1){
return 0
}
for(let i=0;i<prices.length;i++){
for(let j=i+1;j<prices.length;j++){
if((prices-prices)<0){
result.push(0)
}
else{
result.push(prices-prices)
}
}
}
result.sort(function(a, b){return a-b})
return result
};
不知道哪里错了
页:
[1]