Just A Blog


  • 首页

  • 归档

  • 标签

  • 搜索

leetcode:3sum

发表于 2019-12-04 | Visitors
Words count in article 940 | Reading time 4

Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

Note:

The solution set must not contain duplicate triplets.

阅读全文 »

leetcode:permutations

发表于 2019-11-30 | Visitors
Words count in article 791 | Reading time 3

Given a collection of numbers that might contain duplicates, return all possible unique permutations.

阅读全文 »

leetcode:minesweeper

发表于 2019-11-26 | Visitors
Words count in article 597 | Reading time 3

Let’s play the minesweeper game (online game)!

You are given a 2D char matrix representing the game board. ‘M’ represents an unrevealed mine, ‘E’ represents an unrevealed empty square, ‘B’ represents a revealed blank square that has no adjacent (above, below, left, right, and all 4 diagonals) mines, digit (‘1’ to ‘8’) represents how many mines are adjacent to this revealed square, and finally ‘X’ represents a revealed mine.

Now given the next click position (row and column indices) among all the unrevealed squares (‘M’ or ‘E’), return the board after revealing this position according to the following rules:

  • If a mine (‘M’) is revealed, then the game is over - change it to ‘X’.
  • If an empty square (‘E’) with no adjacent mines is revealed, then change it to revealed blank (‘B’) and all of its adjacent unrevealed squares should be revealed recursively.
  • If an empty square (‘E’) with at least one adjacent mine is revealed, then change it to a digit (‘1’ to ‘8’) representing the number of adjacent mines.

Return the board when no more squares will be revealed.

阅读全文 »

leetcode:game of life

发表于 2019-11-26 | Visitors
Words count in article 994 | Reading time 4

According to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”

Given a board with m by n cells, each cell has an initial state live (1) or dead (0). Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article):

  • Any live cell with fewer than two live neighbors dies, as if caused by under-population.
  • Any live cell with two or three live neighbors lives on to the next generation.
  • Any live cell with more than three live neighbors dies, as if by over-population..
  • Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

Write a function to compute the next state (after one update) of the board given its current state. The next state is created by applying the above rules simultaneously to every cell in the current state, where births and deaths occur simultaneously.

阅读全文 »

leetcode:Minimum Moves to Move a Box to Their Target Location

发表于 2019-11-25 | Visitors
Words count in article 1.4k | Reading time 6

The game is represented by a grid of size n*m, where each element is a wall, floor, or a box.

Your task is move the box ‘B’ to the target position ‘T’ under the following rules:

  • Player is represented by character ‘S’ and can move up, down, left, right in the grid if it is a floor (empy cell).
  • Floor is represented by character ‘.’ that means free cell to walk.
  • Wall is represented by character ‘#’ that means obstacle (impossible to walk there).
  • There is only one box ‘B’ and one target cell ‘T’ in the grid.
  • The box can be moved to an adjacent free cell by standing next to the box and then moving in the direction of the box. This is a push.
  • The player cannot walk through the box.

Return the minimum number of pushes to move the box to the target. If there is no way to reach the target, return -1.

阅读全文 »

sort:让计数排序适用性更广吧

发表于 2019-11-25 | Visitors
Words count in article 943 | Reading time 3

计数排序的时间复杂度很低,但是,能够应用的场合就很少了。这个时候,我们就需要对计数排序进行升级

阅读全文 »

sort:如天下第一武道大会般的排序

发表于 2019-11-24 | Visitors
Words count in article 745 | Reading time 2

并归与淘汰赛不得不说的故事

阅读全文 »

sort:让我们来提升一下插入排序的性能吧!

发表于 2019-11-24 | Visitors
Words count in article 967 | Reading time 3

插入排序upupup —> 希尔排序

阅读全文 »

sort:如同整理手牌般的排序

发表于 2019-11-24 | Visitors
Words count in article 495 | Reading time 1

当你在玩扑克之时,庄家发牌的时候,你是怎么处理手上的牌呢?

阅读全文 »

sort:冒泡的另一种进阶方式

发表于 2019-11-24 | Visitors
Words count in article 459 | Reading time 1

论插入排序

阅读全文 »
123…5
ShinyGX

ShinyGX

49 日志
17 标签
RSS
GitHub
© 2021 ShinyGX
由 Hexo 强力驱动
主题 - NexT.Mist
0%