Re: [問題] Google Interview Question (1)

看板Prob_Solve作者 (2-4)時間11年前 (2013/05/12 04:14), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串13/16 (看更多)
※ 引述《pnpncat (meow)》之銘言: : ※ 引述《RockLee (Now of all times)》之銘言: : 1. 將A, B, C分別放進stackA, stackB, stackC : 2. 以下列函數判別答案是否為真 : bool foo() { : while ( stackC is not empty ) { : if ( top of stackC == top of stackA ) { : pop stackC; : pop stackA; : } else if (top of stackC == top of stackB ) { : pop stackC; : pop stackB; : } else { : return false; : } : } : return true; : } 我覺得stack 可行 問題就是要解決怎麼re trace stack tempA while C not empty if (top of stackA = top of stackB = top of stackC){ pop C top of A add to end of tempA pop A } else if (top of stackA = top of stackC){ if(tempA is not empty){ top of A add to tempA } pop A pop C } else if (top of B = top of C){ if (tempA is not empty){ if (top of C = top of tempA){ pop tempA } else return false } pop B pop C } else { var temp = pop tempA if(temp = top of B){ push (A, temp) pop B temp = pop B if (top of C != temp) return false pop C } else return false } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 65.30.61.16
文章代碼(AID): #1HZgQrNF (Prob_Solve)
討論串 (同標題文章)
文章代碼(AID): #1HZgQrNF (Prob_Solve)