JinFei's Blog

Thinking will not overcome fear but action will.

[LeetCode]64. Minimum Path Sum

dp

题目描述 Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Example: Input: <br> ...

[LeetCode]62. Unique Paths

dp使用,状态转移方程推导

题目描述 A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to r...

[LeetCode]200. Number of Islands

dfs遍历搜索

题目描述 Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You...

[LeetCode]448. Find All Numbers Disappeared in an Array

水题

题目描述 Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this...

[LeetCode]198. House Robber

dp,转移方程的推导

题目描述 You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adj...

[LeetCode]3543. Diameter of Binary Tree

二叉树的直径

题目描述 Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path m...

[剑指Offer]扑克牌顺子

排序算法的应用

题目描述 请实现一个函数用来找出字符流中第一个只出现一次的字符。例如,当从字符流中只读出前两个字符”go”时,第一个只出现一次的字符是”g”。当从该字符流中读出前六个字符“google”时,第一个只出现一次的字符是”l”。 输出描述 如果当前字符流没有存在出现一次的字符,返回#字符。 解题思路 由于是字符序列,可以用一个256大小的表来表示这个字符流 talb...

[剑指Offer]复杂链表的复制

链表复制

题目描述 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序会直接返回空) 解题思路 第一步,将链表各个节点复制 第二步,复制random指针 第三步,将链表拆成两个链表(头指针单独处理) /* struct Ra...

[剑指Offer]二叉树中结点值的和为输入整数的所有路径

二叉树指定值

题目描述 输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。(注意: 在返回值的list中,数组长度大的数组靠前) 解题思路 用一个vector代表当前路径 检查当前节点是否是叶子节点 如果是叶子节点,判断是否等于给定的值 如果不是,递归的查找 返回时,记得把当...

[剑指Offer]顺时针打印矩阵

数组打印

题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10. 解题思路 顺时针打印就是按圈数循环打印, 其中圈数circle = (min(row, c...