Hacker Rank:two strings-thinking in C # 15+ ways

Source: Internet
Author: User

March 18, 2016

Problem Statement:

https://www.hackerrank.com/challenges/two-strings/submissions/code/18506948

Julia likes to try a new from train herself to expand c#/C + +/Java/javascript languages, by reading the solutions, F Ollowed up with some study for small topics, make learning more fun.

Coding-write code, read code, memorize some classical code, practice it days.

Julia ' s C # implementation:

1. https://gist.github.com/jianminchen/f73e37b764147cd19c7b

Julia reads 10C # Solution, C + +, Java, JavaScript Solutions, she likes to the extensive reading on software code, and then, build up her daily Routine as a software programmer. Coding is the most important skills,
C #-Read first, then write
C + +-Read more C + + code, prepare to write any time
Java-read more
Javascript-julia tries to read more JavaScript code, focus on reading for next 2 months


She also likes the following C # solution by other submissions:

Https://www.hackerrank.com/challenges/two-strings/leaderboard/filter/language=csharp

Before you read the solution, can-think about using C # Hashset, Dictionary, String.contains, Hashset.overlap method, S Tring.indexof, Hashtable, String. Intersect etc. solve the problem?

Hashset,
Dictionary,
String.contains,
Hashset.overlap method,
String.IndexOf,
Hashtable,
string. Intersect
Using The pointer to solve the problem

2.Use hashset-more efficient
https://gist.github.com/jianminchen/acedbb7cb86cf1c00131

Read HashSet constructor: <-Excellent, Julia is learning to write new C # code
https://msdn.microsoft.com/en-us/library/bb301504 (v=vs.110). aspx

ToList
https://msdn.microsoft.com/en-us/library/bb342261 (v=vs.100). aspx

https://msdn.microsoft.com/library/bb534972 (v=vs.100). aspx

3.using String.intersect method
Https://gist.github.com/jianminchen/cece566bd69963533e80

4.using C #, Var, foreach, any method-interesting to read
https://gist.github.com/jianminchen/50fc6b5a13b7d62dfa1d

5.ienumerable-interesting to read the code
Https://gist.github.com/jianminchen/cdba6a97769db30c2e76

Read ienumberable:c++ Analog-duck Typing
Http://stackoverflow.com/questions/8764643/is-there-a-standard-c-equivalent-of-ienumerablet-in-c

Ienumberable-java Analog
Http://stackoverflow.com/questions/362367/java-arrays-generics-java-equivalent-to-c-sharp-ienumerablet

6.hashsets
Https://gist.github.com/jianminchen/aa87f82f0247c4b59ab6

7.Hashset-overlaps Method-Code is readable
https://gist.github.com/jianminchen/b28fab138ad778bc4326

Read Hashset overlap Api-learn some design:
https://msdn.microsoft.com/en-us/library/bb355623 (v=vs.110). aspx

8.Array, Array.BinarySearch method-It is not the time efficient Solution-but code is reusable.
Https://gist.github.com/jianminchen/775cf5e16d065e66feae

9.Declare new struct data, use byte type, and code is beautiful, succinct.

Https://gist.github.com/jianminchen/9d80b3995adf0b01f9d7

10.Use pointers, move forward if need separately-Can be reused.

https://gist.github.com/jianminchen/7de04dcfb8740ee19412

One. Things Julia likes:
' Z '-' a ' in array declaration,
Second one is to use one array int[26], not 2; Second one is char array

https://gist.github.com/jianminchen/de154d443a1434094260

Bool[] founded =Newbool[' Z‘ -' A' +1];
char[] Secondword = Console.ReadLine (). ToCharArray ();

12.Use Hashtable
Https://gist.github.com/jianminchen/213335b4dec3988facfe

13.Use string. Contains () method
Https://gist.github.com/jianminchen/6388585c990a42ea76ae

14.Use Dictionary class
https://gist.github.com/jianminchen/95b701e6d2146da13c1d

Dictionary<int, char>
dictionary<Intchar> dex =New dictionary<IntChar> ();
Dictionary Method Containsvalue ()

15.string. ToCharArray (), Distinct () of Char Array, ToList (), ToArray (), String. IndexOf Methods
Https://gist.github.com/jianminchen/7562c5dd310508d48f58

. Usestring. Contains,Dimension Array
https://gist.github.com/jianminchen/365eb2b69e93573c0b5d

Use Dictionary<char, bool>
Https://gist.github.com/jianminchen/a91504a793f795886e23

. UseStringBuilderTo concatenate output

Https://gist.github.com/jianminchen/1fcc46803321f007eb1b

Read the discussion StringBuilder vs string to concatenation
Http://stackoverflow.com/questions/1612797/string-concatenation-vs-string-builder-performance

https://support.microsoft.com/en-us/kb/306822

More Reading:1

the use "" to concatenate the input strings and then. Split them
https://gist.github.com/jianminchen/591738de12e21e591634

More Julia likes:
IEnumerable-
https://www.hackerrank.com/rest/contests/master/challenges/two-strings/hackers/cdkmoose/download_solution




Statistics:

More than 3 hours to work on this study, thinking in C #-

Advice for C # programmers:

Julia enjoyed the study. Very Focus, try to understand the solution, what other people think in C #. It's The Big world, millions programmers in the world today, and you had to go out to reach them, some wisdom out there, tea CH you to learn C # programming language in very organic.

No One person can put together so many ideas for a simple problem.

Julia is proud of herself, come to some simple idea to train herself in algorithm thinking. Low cost, and easy to access, and good quality code.

More reading:
. UseStringBuilderTo concatenate output

Here is good ideas for Julia to be a better C # developer as the anonymous code writer in 18:
(from webpage:https://support.microsoft.com/en-us/kb/306822)
1. The benefits of using the StringBuilder class over traditional concatenation techniques
2. C + + strcat ()-to allocate a large character array as a buffer and copy string data into the buffer.
3. The. NET framework, a string is immutable; It cannot is modified in place. <-Immutable explanation!
4. The C # + concatenation operator builds a new string and causes reduced performance when it concatenates large Amoun TS of text.
5. The. NET framework, a StringBuilder class is optimized for string concatenation.
same as using a character array in C + +, as well as automatically growing the buffer size (if needed) and tracking th e length for you.
6. Reuse existing StringBuilder class rather Tahn reallocate each time you need one. This limits the growth of the heap and reduces garbage collection. StringBuilder makes more efficient use of the heap than using the + operator.

Hacker Rank:two strings-thinking in C # 15+ ways

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.