We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Both my code and the top two codes in discussions are terminated due to timeout. I don't know how to reduce the runtime anymore. Could anyone successfully solving this problem point out the pitfalls in my code? The version 1 of the following code is my code. The version 2 is quoted from Discussions.
// Version 1 - Phoenix(me)template<classT>classAddElements{Te1;public:AddElements(Targ){e1=arg;}Tadd(Te2){returne1+e2;}};template<>classAddElements<string>{stringe1;public:AddElements(stringstr){e1=str;}stringconcatenate(stringe2){returne1+e2;}};// Version 2 - kk65g3template<classT>classAddElements{public:Telement;AddElements(Ti){element=i;}Tadd(Ti){returnelement+i;}private:};template<>classAddElements<string>{public:stringelement;AddElements(stringi){element=i;}stringconcatenate(stringelement2){returnelement+element2;}private:};
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
C++ Class Templates
You are viewing a single comment's thread. Return to all comments →
Both my code and the top two codes in discussions are terminated due to timeout. I don't know how to reduce the runtime anymore. Could anyone successfully solving this problem point out the pitfalls in my code? The version 1 of the following code is my code. The version 2 is quoted from Discussions.