tag:blogger.com,1999:blog-2597841815280998418.post7646580539389424545..comments2024-03-12T06:45:01.935+01:00Comments on This Thread: Codility DistinctMannyhttp://www.blogger.com/profile/07393063644320426727noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-2597841815280998418.post-59802687853400383012016-04-30T14:36:00.369+02:002016-04-30T14:36:00.369+02:00It's a pity that copy and paste ruined the cod...It's a pity that copy and paste ruined the code for both solution, still it is clear the idea behind. There is no need of sorting, just think to the set container.<br />A set has the cool property of discarding duplicates, so I should just copy the elements from the vector to the set, and then checking how many elements make it to it.<br />But now that I think about it, we can do even better.Mannyhttps://www.blogger.com/profile/07393063644320426727noreply@blogger.comtag:blogger.com,1999:blog-2597841815280998418.post-21544652829649484022016-03-22T15:09:43.035+01:002016-03-22T15:09:43.035+01:00int solution(vector &A) {
set distinct(A....int solution(vector &A) {<br /><br /> set distinct(A.begin(), A.end());<br /> return distinct.size();<br /><br />}Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2597841815280998418.post-36973641472855204272015-10-18T14:18:32.491+02:002015-10-18T14:18:32.491+02:00#include
int solution(vector &A) {
// wri...#include <br />int solution(vector &A) {<br /> // write your code in C++11<br /> set myset;<br /> for(auto&a : A) myset.insert(a);<br /> return myset.size();<br />}<br />Anonymousnoreply@blogger.com