leetcode笔记--7 Find the Difference】的更多相关文章

question: 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. my answer: 代码看起来有些长,目前还没有想到更好的办法 思…
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 return [ [5,4,11,2],…
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11…
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more tha…
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. Tags: Depth-first Search 分析 很基本的一道深度优…
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space is pretty straight forward. Could you devise a constan…
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right…
题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note: B…
题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. You may assume that there will be only one unique solution. A sudoku puzzle... ...and its solution n…
题目链接:Valid Sudoku | LeetCode OJ Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially filled sudoku which is valid. Note:…
题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only u…
题目链接:Populating Next Right Pointers in Each Node | LeetCode OJ Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node. If there is no next ri…
目录 leetcode笔记 动态规划在字符串匹配中的应用 0 参考文献 1. [10. Regular Expression Matching] 1.1 题目 1.2 思路 && 解题方法 1.3 实现 2. [44. Wildcard Matching] 2.1 题目 2.2 思路 && 解题方法 2.3 实现 3. [97. Interleaving String] 3.1 题目 3.2 思路 && 解题方法 3.3 实现 leetcode笔记 动态规划…
0.问题描述 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置. 你可以假设数组中无重复元素. 示例 1: 12 输入: [1,3,5,6], 5输出: 2 示例 2: 12 输入: [1,3,5,6], 2输出: 1 示例 3: 12 输入: [1,3,5,6], 7输出: 4 示例 4: 12 输入: [1,3,5,6], 0输出: 0 1.问题分析 典型的二分查找,虽然不知道leetcode的数据为什么暴力搜索比二分法的…
Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Try to solve it in linear time/space. Return 0 if the array contains less than 2 elements. You may assume all elements in the array are non-negat…
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. leetcode的题目真是越来越经典了.比如这个题目,就是一道男默女泪的题. 一般人拿到这个题目,除非做过类似的,很难一眼找出一个方法来,更别说找一个比较优化的方法了. 首先一个难点就是,你怎么判断某个区域就是一个矩形呢? 其次,以何种方式来遍历这个2D的…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcode.com/problems/minimum-absolute-difference/ 题目描述 Given an array of distinct integers arr, find all pairs of elements with the minimum absolute differen…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:https://leetcode.com/problems/minimum-absolute-difference-in-bst/#/description 题目描述 Given a binary search tree with non-negative values, find the minimu…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/minimum-time-difference/description/ 题目描述: Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minutes difference between…
82. Remove Duplicates from Sorted List II https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ 下面代码是自写hashmap版,练一下hashmap,用一般的map<int,int>红黑树map也能过. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *…
题目: Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of j…
-------------------------------------------------- 先计算每个字母的出现次数然后减去,最后剩下的那一个就是后来添加的了. AC代码: public class Solution { public char findTheDifference(String s, String t) { int book[]=new int[26]; for(int i=0;i<s.length();i++) book[s.charAt(i)-'a']++; for…
题目: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…
Given an array of integers, every element appears three times except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 没辙,智商碾压题.楼主没遇到之前就只会这种做法. public int si…
前言 之前把一些LeetCode题目的思路写在了本子上,现在把这些全都放到博客上,以后翻阅比较方便. 题目 99.Recover Binary Search Tree 题意 Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. 恢复两个因错误而导致的左右子树. 思路 通常我们的做法是,根据BST的特质,可以用中序遍历来检…
这是悦乐书的第253次更新,第266篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第120题(顺位题号是530).给定具有非负值的二叉搜索树,找到任意两个节点的值之间的最小绝对差.例: 输入: 1 \ 3 / 2 输出:1 说明:最小绝对差值为1,即2和1之间(或2和3之间)的差值. 注意:此BST中至少有两个节点. 本次解题使用的开发工具是eclipse,jdk使用的版本是1.8,环境是win7 64位系统,使用Java语言编写和测试. 02 第一种解法 题目的要…
这是悦乐书的第214次更新,第227篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第82题(顺位题号是389).给定两个字符串s和t,它们只包含小写字母.字符串t由随机混洗字符串s生成,然后在随机位置再添加一个字母.找到t中添加的字母.例如: 输入:s ="abcd", t ="abcde" 输出:'e' 说明:'e'是添加的字母. 本次解题使用的开发工具是eclipse,jdk使用的版本是1.8,环境是win7 64位系统,使用Jav…
题目:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S = "ADOBECODEBANC"T = "ABC" Minimum window is "BANC". Note:If there is no such windo…
题目:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m + n) space, but sti…
题目:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example,  Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. 例如给出上图中的黑色部分(数组表示),让你求出蓝色部分. 这也是个神题...当…