Skip to content

SandWind/leetcode-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About it

Algorithm is tool for exercising our thinking patterns, and we can strengthen the ability to convert mathematical models into code. Whether you are engaged in artificial intelligence, in-depth learning, or advanced software development, no matter what language you use, such as C#,C++,Java,python,etc., and applying the most appropriate algorithm is always the most important point when faced with a specific problem. Every problem in practice has its own particularity, which makes it not that easier to choose the most appropriate algorithm. How do we write the algorithm that most efficiently apply to a practical issue? Yes, LeetCode. You can write an algorithm until it accepted, and do not rush to do the next question, and learn the solution someone else has submitted, so you can solve the problem from the ability of solving the problem to that fast and efficient realm.

I create this respository called leetcode-csharp because I apply C# language to solove LeetCode and every day will update it and also publish it in CSDN blog(http://blog.csdn.net/daigualu) my blog column(http://blog.csdn.net/column/details/14761.html) Also, I will write some famous algorithm ideas on My Wiki for this repository such asFlody tortoise and hare and KMPand so on.

Anyway, welcome to view, star and fork, then contribute.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-leetcode-csharp
  3. Commit your changes: git commit -am 'Add some questions and better solutions'
  4. Push to the branch: git push origin my-leetcode-csharp
  5. Submit a pull request and enjoy! :D

Today Update

Math

400 Nth Digit

  • Github:#400 Nth Digit
  • CSDN:#400 Nth Digit
    • Tips:
      • careful to prevent overflowing for bas*digits, so declaring bas is long.
            //for this issue, there are two different ways to decribe a number
         //1 element. this is our common way
         //2 Nth digit. this is a new way
         public int FindNthDigit(int n)
         {
             long bas = 9;
             int digits = 1, i = 0;
             //first: getting n which digit is in
             while (n > bas * digits) // prevent overflowing. Since bas is long, so result of bas*digits is auto imporved as long
             {
                 n -= (int)(bas * (digits++)); //nth
                 i += (int)bas; //number of pasted elements
                 bas *= 10; //1 digit->9; 2 digits->90; 3 digits->900, ...   
             }
             //second: Nth digit ->element
             //in all numbers containing digits, pasted numbers
             int pasted = (int)((n - 1) / digits);
             int element = pasted + i + 1;
             //third: once getting the element Nth digits stands,
             //(n-1)%digits of element is solution
             int nth = (n - 1) % digits;
             return element.ToString()[nth] - '0';
         }

69 Sqrt(x)

  • Github:#69 Sqrt(x)
  • CSDN:#69 Sqrt(x)
    • Tips:
      • careful to prevent overflowing! Again careful to overflow!
         public int MySqrt(int x)
         {
             int lo = 0, hi = x ;
             while (lo - hi < -1)
             {
             //get [lo,hi] middle point,then compare pow2 to x,
             // lo or hi is setted by mid
             //so accelarate the process
                 long mid = lo + (hi - lo) / 2; //prevent overflowing
                 long pow2 = mid * mid; //prevent overflowing
                 if (pow2 < x) lo = (int)mid;
                 else if (pow2 > x) hi = (int)mid;
                 else return (int)mid;
             }
             return lo;
         }


Solution List

solutions using C# for leetcode according to tags of questions Tags are following:

Details

Array

532 K-diff Pairs in an Array

217 Contains Duplicate

448 Find All Numbers Disappeared in an Array

219 Contains Duplicate II

189. Rotate Array

448 Find All Numbers Disappeared in an Array

219 Contains Duplicate II

566 Reshape the Matrix

561 Array Partition I

Hash Table

242 Valid Anagram

561 Array Partition I

438 Find All Anagrams in a String

204 Count Primes

500 Keyboard Row

389 Find the Difference

380 Insert Delete GetRandom O(1)

451 Sort Characters By Frequency

575 Distribute Candies

381 Insert Delete GetRandom O(1) - Duplicates allowed

Linked List

Math

7 Reverse Integer

202 Happy Number

453 Minimum Moves to Equal Array Elements

415 Add Strings

Two Pointers

#234Palindrome Linked List

String

Binary Search

Tree

144 Binary Tree Preorder Traversal Stack version

94 Binary Tree Inorder Traversal Stack version

572 Subtree of Another Tree

103 Binary Tree Zigzag Level Order Traversal

95 Unique Binary Search Trees II

105 Construct Binary Tree from Preorder and Inorder Traversal

About

solutions using C# for leetcode according to tags of questions, updating everyday. My contact info: [email protected] or my blog: http://blog.csdn.net/daigualu

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%