摘要:题解 逆序链表,基本功之一。 用递归写起来很简单,但需要消耗大量栈空间,更推荐使用迭代的方法。通过画图找到变换关系。 // Original Linked List: ? --> p --> q --> r --> ? // Assume the elements before p have bee
阅读全文
摘要:题解 这道题是Easy级别,算是BFS的典型题,适合用来找手感。 非常典型的套路是,用一个队列结构(queue)保存一层的信息,那么下一次迭代的时候,就可以通过队列先进先出的顺序,根据上一层的信息去操作。 class Solution { public: vector<vector<int>> le
阅读全文
摘要:题述 原题见链接。 题解 根据题意,很容易想到蛮力解法如下: Brute Force Method // Complete the arrayManipulation function below. long arrayManipulation(int n, vector<vector<int>>
阅读全文
摘要:Description: There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each
阅读全文
摘要:[Problem] Given a 2D grid, each cell is either a wall 2, an house 1 or empty 0 (the number zero, one, two), find a place to build a post office so tha
阅读全文
摘要:[Probelm] (link) Given a 2D grid, each cell is either a wall 2, a zombie 1 or people 0 (the number zero, one, two).Zombies can turn the nearest people
阅读全文
摘要:[Problem] Given a knight in a chessboard (a binary matrix with 0 as empty and 1 as barrier) with a source position, find the shortest path to a destin
阅读全文
摘要:[Problem] Given a undirected graph, a node and a target, return the nearest node to given node which value of it is target, return NULL if you can't f
阅读全文