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

作者: afafaf (bb)   2013-04-16 23:13:51
※ 引述《RockLee (Now of all times)》之銘言:
: 原始網址:
: http://www.careercup.com/question?id=14539805
: 題目:
: Three strings say A, B, C are given to you.
: Check weather 3rd string is interleaved from string A and B.
: Ex: A="abcd" B="xyz" C="axybczd". answer is yes. o(n)
: 用 Dynamic Programming 應該可在 O(n^2) 的時間內解決
: 但要在 O(n) 的時間內解決就想不出來了 Orz...
: CareerCup 上的討論看來都無法在 O(n) 的時間內正確的解決
: 不知道板上有沒有人有什麼 idea?
int arr[26] = {0}, 代表a~z counter
把A, B的字母遇到則加, C的字母遇到則減,
最後check arr是否全0, O(n)吧
作者: suhorng ( )   2013-04-16 23:29:00
順序呢? A=ab, B=c, C=cba

Links booklink

Contact Us: admin [ a t ] ucptt.com