原题 Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was added in t. Example: Input: s = "abcd" t = "…
[LeetCode]120. Triangle 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址https://leetcode.com/problems/triangle/description/ 题目描述: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjac…
[题意] 给两个字符串s和p,判断s是否能用p进行匹配. [题解] dp[i][j]表示s的前i个是否能被p的前j个匹配. 首先可以分成3大类情况,我们先从简单的看起: (1)s[i - 1] = p[j - 1],易得dp[i][j] = dp[i-1][j-1] (2)p[i - 1] = '.',因为'.'可以匹配任何字符,所以dp[i][j] = dp[i-1][j-1] (3)p[i - 1] = '*',这种情况就比较复杂了. 当p[j - 2] != s[i - 1] &&…
https://blog.csdn.net/styshoo/article/details/52865386 在LeetCode中,TreeNode是经常用到的一个结构体,表示数据结构树(Tree)中的一个节点.其官方定义如下: public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; }}123456 在Tree的题目中,常会给出一些测试用例,用一些特定的格式来表示一棵树…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:字典统计次数 方法二:异或 方法三:排序 日期 [LeetCode] https://leetcode.com/problems/find-the-difference/ Difficulty: Easy 题目描述 Given two strings s and t which consist of only lowercase letter…
Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in the array, return [-1, -1]. For example,Given [5, 7,…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetcode.com/problems/n-queens/ 题目描述 The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/h-index/description/ 题目描述: Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's…
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the values in the list, onl…
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is. You may not alter the values in the nodes, only nod…