代码改变世界

[LeetCode] 系统刷题7_Array & numbers & string

2019-05-09 11:22  Johnson_强生仔仔  阅读(346)  评论(0编辑  收藏  举报

1. 2 D Array

  • 如果是在左上到右下的斜线的话,在同一条斜线上的x - y 相等, (x, y) 是该点的坐标
  • 如果是在左下到右上的斜线的话,在同一条斜线上的x + y 相等, (x, y) 是该点的坐标

    ex. [(1, 1),  (1, 2),  (1, 3)]

         [(2, 1), (2, 2), (2, 3)]

     [(3, 1), (3, 2), (3, 3)]

  • 行变列     matrix   => zip(*matrix)

   ex.  matrix = [[ 1,  2,  3],      =>    list(zip(*matrix))  = [ (1, 4, 7),

             [ 4,  5, 6],               (2, 5, 8), 

        [ 7,  8, 9]]               (3, 6, 9)]

  • 对于9 * 9 数独, cellIndex = (row //3) * 3 + col //3 ;  另外如果要遍历在(row, col)位置的小正方形的9个位置,利用newRow =  (row //3) * 3 + k //3, newCol =  (col //3) * 3 + k %3 for k in range(9).

2. Sorted array

  •     Rotated sorted array

    [LeetCode] 189. Rotate Array_Easy tag: Array

Recover Rotated Sorted Array

Reverse Words in a String

    [LeetCode] 796. Rotate String_Easy **KMP

  •     Merge sorted array

    [LeetCode] 88. Merge Sorted Array_Easy tag: Two Pointers

        Merge Sorted Array II

    [LeetCode] 4. Median of Two Sorted Arrays_Hard tag: Array

  •   Subarray

 

             Best Time to BUy and Sale Stock I, II, III

    - Prefix Sum

    [LeetCode] 560.Subarray Sum Equals K_Medium tag: Array, Subarray, prefix Sum

  •   Two pointers

    [LeetCode] 15. 3Sum_Medium tag: Array

    [LeetCode] 167. Two Sum II - Input array is sorted_Easy tag: Hash/Two pointers

    [LeetCode] 5. Longest Palindromic Substring _Medium tag: Two pointers

    [LeetCode] 904. Fruit Into Baskets_Medium tag: Two pointers

    [LeetCode] 3. Longest Substring Without Repeating Characters_Medium tag: two pointers

    [LeetCode] 11. Container With Most Water_Medium tag: two pointers

    [LeetCode] 31. Next Permutation_Medium tag: sort, two pointers

    [LeetCode] 76. Minimum Window Substring_Hard tag: two pointers

    [LeetCode] 159. Longest Substring with At Most Two Distinct Characters_Medium tag: Two pointers

    [LeetCode] 809. Expressive Words_Medium tag: array, two pointers

    [LeetCode] 259. 3Sum Smaller_Medium tag: Two pointers

 

          2 - Sum, 3 Sum, 4 - SUm, K- SUM, 3- Sum Closest.

          Partition Array

  • Sorting

    [LeetCode] 56. Merge Intervals_Medium Tag: sort 

    [LeetCode] 252. Meeting Rooms_Easy tag: Sort

    [LeetCode] 763. Partition Labels_Medium Tag: sort

    [LeetCode] 347. Top K Frequent Elements_Medium tag: Array, Heap

    [LeetCode] 973. K Closest Points to Origin_Easy tag: Sort

    [LeetCode] 681. Next Closest Time_Medium tag: array, sort

 

 

          SOrt letters by Case

    [LeetCode] 75. Sort Colors_Medium tag: Two pointers

        INterleaving Negative & positive numbers

 3. Palindrome

    [Palindrome] Check any substring in a s is a palindrome or not.

    [LeetCode] 131. Palindrome Partitioning_Medium tag: DFS, backtracking, Palindrome

    [LeetCode] 5. Longest Palindromic Substring _Medium tag: Two pointers

4. String

    [LeetCode] 482. License Key Formatting_Easy tag: String 

    [LeetCode] 43. Multiply Strings_Medium tag: string

 

Math:

[LeetCode] 812. Largest Triangle Area_Easy tag: math

[LeetCode] 382. Linked List Random Node_Medium tag: linked list, math

 

bit 

---待整理 ----

1542. Find Longest Awesome Substring