Minimum Path Sum

Description https://oj.leetcode.com/problems/minimum-path-sum/ Difficulty: 1.5/5.0 star Analysis and solution This is an problem easy to solve. One thing worth noting is that we do not need BFS with a 2D-array. Two-layer loop with 1D-array is quite enough, as we only move...

Binary Tree Level Order Traversal II

Description https://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/ Difficulty: 0.5/5.0 star Related: https://oj.leetcode.com/problems/binary-tree-level-order-traversal/ Analysis and solution It is almost the same with the old problem. All you have to do is to reverse the result vector. class Solution { public: vector<vector<int> > levelOrderBottom(TreeNode *root) { vector<vector<int>...

Rotate Image

Description https://oj.leetcode.com/problems/rotate-image/ Difficulty: 1.5/5.0 star Analysis and solution We enumerate each block in the pink area and swap the four purple blocks following the arrows. class Solution { public: void rotate(vector<vector<int> > &matrix) { int n = matrix.size(); int tmpSwap;...

Permutations II

Description https://oj.leetcode.com/problems/permutations-ii/ Difficulty: 3.0/5.0 star Related: https://oj.leetcode.com/problems/permutations/ Analaysis There are at least three solutions to this prolem, corresponding to the three solutions to Permutations I respectively. The first one is still the DFS, with a redundancy elimination step. class Solution...

Permutations

Description https://oj.leetcode.com/problems/permutations/ Difficulty: 0.5 or 3.0/5.0 star Related: https://oj.leetcode.com/problems/permutations-ii/ Analysis and solution The first solution is failry easy to come up with. It is a DFS solution with a visited array for checking if a number is used or not....