我制定了以下邏輯。最短運行:具有相同元素的原始數組的子數組。如何查找數組中最短運行的最後一個索引?
// "A" is Array, p is length of a current run, q is global variable that stores lowest run length
procedure(){
while(i < sizeOfArray){
if(A[i]==A[i+1]){
//1.Increment a variable "p" to capture the length of run
//2. compare p and q and which ever is smaller , is saved into q
}else{
//3. What to do here ?
}
}
return q;
}
仍然無效的C代碼。你的問題表明你的邏輯「總是返回錯誤。」這是什麼意思,如果你還沒有寫任何代碼呢?相關的邏輯不是以你所表現出來的方式表達的。你將需要努力讓任何人來幫助解決這個問題。 –
@DavidBowling我重申了這個問題。提問的動機是瞭解邏輯而不是編程代碼。您可以使用任何語言來顯示答案。謝謝 – djay