LeetCode 题解之Rotate List
1、题目描述 2、题目分析 首先数出链表中的元素个数count,然后对k = k % count 求余数。接着将链表形成一个环,从最后一个元素开始,运动 count - k 步,此时节点的下一个节点就是结果的头节点。 3、代码 1 ListNode* rotateRight(ListNod...
[LeetCode]题解(python):116 Populating Next Right Pointers in Each Node
题目来源https://leetcode.com/problems/populating-next-right-pointers-in-each-node/Given a binary tree struct TreeLinkNode { TreeLinkNode *left; ...
[LeetCode]题解(python):055-Jump Game
题目来源https://leetcode.com/problems/jump-game/Given an array of non-negative integers, you are initially positioned at the first index of the array.Each...
[LeetCode]题解(python):064-Minimum Path Sum
题目来源https://leetcode.com/problems/minimum-path-sum/Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whic...
leetCode题解之求二叉树每层的平均值
1、题目描述Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.计算二叉树每一层的节点的数据域的平均值。2、题目分析使用广度优先遍历方法,...
leetCode题解之Contains Duplicate
1、题目描述2、题目分析直接使用hashTable 计数,超过1 则返回true,最后返回 false即可。3、代码 bool containsDuplicate(vector<int>& nums) { if( nums.size() == ) ...
LeetCode题解-----Majority Element II 摩尔投票法
题目描述:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) spac...
LeetCode题解之Contains Duplicate II
1、题目描述2、题目分析使用哈希表 和分情况讨论的方法3、代码bool containsNearbyDuplicate(vector<int>& nums, int k) { if( nums.size() == ){ return fals...
[LeetCode]题解(python):101 Symmetric tree
题目来源https://leetcode.com/problems/symmetric-tree/Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).题意分析Inp...
Leetcode题解(八)
26、Remove Duplicates from Sorted Array题目直接上代码,方法很简单:class Solution {public: int removeDuplicates(vector<int>& nums) { const int si...
LeetCode题解33.Search in Rotated Sorted Array
33. Search in Rotated Sorted ArraySuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 m...
[LeetCode]题解(python):030-Substring with Concatenation of All Words
题目来源https://leetcode.com/problems/substring-with-concatenation-of-all-words/You are given a string, s, and a list of words, words, that are all of the...
[LeetCode]题解(python):026-Remove Duplicates from Sorted Array
题目来源:https://leetcode.com/problems/remove-duplicates-from-sorted-array/题意分析:给定一个排好序的数组,去除重复的数,返回新数组的长度,不能申请额外的空间,超过新数组长度部分是什么数都无所谓。题目思路:这是一个很简单的题目,由于给...
LeetCode题解——Longest Palindromic Substring
题目:给定一个字符串S,返回S中最长的回文子串。S最长为1000,且最长回文子串是唯一。解法:①遍历,对于每个字符,计算以它为中心的回文子串长度(长度为奇数),同时计算以它和右边相邻字符为中心的回文子串长度(长度为偶数)。时间为O(N2)。②另外,有一个很奇妙的算法,称为Manacher算法,参考 ...
【题解】【排列组合】【素数】【Leetcode】Unique Paths
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 po...
[LeetCode 题解]: Validate Binary Search Tree
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...
C++版 - 剑指offer 面试题16:反转链表(Leetcode 206: Reverse Linked List) 题解
面试题16:反转链表提交网址: http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca?tpId=13&tqId=11168或 https://leetcode.com/problems/reverse-linked...
LeetCode Database题解
175. Combine Two Tables使用外连接即可。# Write your MySQL query statement belowselect FirstName, LastName, City, State from Person left outer join Address on ...
[LeetCode]题解(python):044-Wildcard Matching
题目来源: https://leetcode.com/problems/wildcard-matching/ 题意分析: 定义两个新字符规则,'?'代表任意一个字符,’*‘代表任意长度的任意字符。输入一个s和p,判断s是否能被p匹配。 题目思路: 这题和前面的一个正则表达式类似,不过比前面那...
Leetcode题解---Regular Expression Matching Java实现
leetcode regular expression matching题目链接:https://leetcode.com/problems/regular-expression-matching/#/description 解题思路: (1)匹配串长度为1时,特殊处理 (2)匹配串长度大于1时...