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.
This is how I implemented a custom comparer for comparing two strings. Everything passed without timeouts.
internalclassCustomComparer:IComparer<string>{publicintCompare(stringx,stringy){// If the length is not the same, we return the difference.// A negative # means, x Length is shorter, 0 means the same (this doesn't occur) and a postive # means Y is biggerif(x.Length!=y.Length)returnx.Length-y.Length;// Now the length is the same.// Compare the number from the first digit.for(inti=0;i<x.Length;i++){charleft=x[i];charright=y[i];if(left!=right)returnleft-right;}// Default: "0" means both numbers are the same.return0;}}
Big Sorting
You are viewing a single comment's thread. Return to all comments →
This is how I implemented a custom comparer for comparing two strings. Everything passed without timeouts.