LeetCode November Week 1 topic summary


Open Source Address: Click on this link


Foreword

Over the last month found every day in the form of [a] series of questions and not appropriate to update the title, one is not enough to update the appropriate topic, and second, separate out is not a problem in terms of the system, it should be more a similar topic on talk together, so as to achieve the effect of giving top priority, so I decided to stop [a day] series title changed to [summary] week, then once a month and then monthly summary, then get down to business.

The first week of November a total of 20 questions, all the source code and the corresponding problem-solving ideas even open source to GitHub, a public reply No. "LeetCode" get with the following breakdown.

Mapping

Such common data structure Title: map, unordered_map, set or array using the hash mapping.

  • 0242_valid_anagram
  • 0290_word_pattern
  • 0299_bulls_and_cows
    more than three questions are dual mapping relationships between characters or strings is established, use the map according to the situation, unordered_map or can use an array
  • 0349_intersection_of_two_arrays
  • 0350_intersection_of_two_arrays_ii
    above two questions is to solve the intersection of two arrays, the first question only to find there are several different then, does not care about the number; the second topic need to find out the specific number of the same characters, also count duplicate
  • 0383_ransom_note
    This topic is a query whether a string contains another string of characters not less than the number of

Depth-first search

  • 0257_binary_tree_paths

Riddles

This topic is more interesting, just began to think of a variety of practices, but it feels too complicated, should time out, think Well, look at the official solution to a problem, the result was just a get, I ***, and analytical reading after only say, clothes, and interested can take a look at the official solution, not go into here.

  • 0292_nim_game

mathematics

Such questions are the subject of mathematical methods can be used to solve, not much study data structures.

  • 0258_add_digits
  • 0263_ugly_number
  • 0268_missing_number
    该题目有多种解法,第一种是根据递增数组求解,然后计算差值就可得到确实的数是哪一个;第二种是官方给出的一种,通过异或运算得出,方法很有意思;两种方法复杂度相同
  • 0303_range_sum_query_immutable
    这个题目就是预先计算积分即可,了解图像处理的都知道图像积分这个概念,只不过这里是一维数组,而图像是二维的(不考虑颜色通道时),所以很简单
  • 0326_power_of_three
  • 0342_power_of_four
    这两个题目是判断给定数是否是某个数的幂,最简单的方法就是暴力分解,一种做法是将给定数转化成对应数的进制,即3进制或4进制,转换后的数如果是它的幂,那么一定只含有一个 1,所以判断一下就行了;另一种方法就是如果先找出最大的幂是多少,如果给定数也是,那么最大幂一定可以整除这个数,复杂度为O(1)

二分法

二分法就没什么好说的了,就那些操作,左右各一个,中间数大了右边的往左移动,中间数小了左边的往右移动,直到结束即可。

  • 0278_first_bad_version
  • 0367_valid_perfect_square
  • 0374_guess_number_higher_or_lower

反转数组

反转数组就是使用双指针了,第一个题目直接进行即可,第二个题目只反转元音字母,所以指针移动时不再是++或--操作,而是以元音字母为单位移动,也没什么复杂的。

  • 0344_reverse_string
  • 0345_reverse_vowels_of_a_string

位运算

根据计算机原理,使用二进制的异或和与运算实现加法,其中异或表示加法,与运算表示进位。

  • 0371_sum_of_two_integers

Guess you like

Origin www.cnblogs.com/jiau/p/11826501.html