we can reduce space complexity further more by just maintaining one
array...
a[256]={0,0,0,0,........................................0,0,0,0,0};
As character can be non numeric... all possibility in 256 ..
s[] = input string.
for( i=0;i<strlen(s);i++)
{ a[ s[i] ]++;
}
for( i=0;i<strlen(s);i++)
{ if(a[ s[i] ] > 1)
return s[i] ;
}
On Thu, Oct 14, 2010 at 12:42 AM, Asquare <[email protected]> wrote:
> Thanks :)
> This is definitely a much better option than O(mn)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
*Divesh*
(¨`·.·´¨) Always
`·.¸(¨`·.·´¨ ) Keep
(¨`·.·´¨)¸.·´Smiling!
`·.¸.·´" Life can give u 100's of reason 2cry,but u can give life 1000's
of reasons 2Smile"
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.