
LeetCode
文章平均质量分 62
v_xchen_v
这个作者很懒,什么都没留下…
展开
-
【剑指offer题解 整理版】树
树考察点树的下一个结点对称二叉树镜像二叉树把二叉树打印成多行按之字形顺序打印二叉树从上往下打印二叉树序列化与反序列化二叉树二叉树中和为某一值的路径二叉树的深度二叉搜索树的第k个结点二叉搜索树与双向链表树考察点树的数据结构特性 - 树的遍历规律、遍历序列特点 - 树的下一个结点 - 树与递归 - 对称二叉树 ...原创 2018-08-26 21:55:39 · 1132 阅读 · 0 评论 -
LeetCode 3. Longest Substring Without Repeating Characters(C++)
这道题我是强行调出来的,花了很长时间,大概思路是,使用map存储遍历的字符与字符位置(用于比较是否有重复字符),start和end标记符合条件的序列的开始位置和结束位置,如果遇到重复的字符,就移动start到end这,end+1,并清空map。感觉解的太麻烦了,肯定有更简洁的解法。class Solution {public: int lengthOfLongestSubstri原创 2017-03-22 13:56:21 · 1229 阅读 · 0 评论 -
LeetCode 2. Add Two Numbers(C++)
使用了O(1)的额外空间,思路是将两个链表遍历并合并,合并过程中不断计算进位,如果计算到最后一次加法仍有进位(可能是两个链表对应位置值相加产生进位或者上一次的进位加本次值又产生进位),那么需要加一个值为1的新结点。这种思路的优点是空间复杂度小,缺点是实现比较复杂(跟借助一个额外的数组和链表相比)。/** * Definition for singly-linked list. * st原创 2017-03-21 20:11:37 · 1137 阅读 · 0 评论 -
LeetCode 4. Median of Two Sorted Arrays(c++)
问题:求两个有序数组合并后的中间值思路:如果两个序列长度和为偶数,就找合并后序列的两个中间的数求平均值,如果两个序列的长度和为奇数,就直接返回合并后序列的最中间的数。0...m和0...n合并后0... ((m+n)-1)/2 ...m+n(奇数长)^|0...m和0...n合并后0... ((m+n)-1)/2 ((m+n)-1)/2+1 ...m+n(偶数长)^ ^原创 2017-03-25 21:49:25 · 321 阅读 · 0 评论 -
LeetCode 5. Longest Palindromic Substring(C++)
问题:找字符串中的最长回文子串思路:设立两个标志pre和after从每个字符开始向左右两边查询,如果s[pre]!=s[after]或者超出范围,那么该字符出发的最长回文子串为s[pre+1,...,after-1]。初始状态分别为pre=after=i和pre=i,after=i+1对应ABA和ABBA两种不同的回文情况。遍历维护maxLen即可找打最长回文子串。cl原创 2017-03-25 22:17:36 · 454 阅读 · 0 评论 -
LeetCode 12 Integer to Roman题解
题目地址:https://leetcode.com/problems/integer-to-roman/题目:Given an integer, convert it to a roman numeral.给定一个数,将它转化为罗马数值。Input is guaranteed to be within the range from 1 to 3999.原创 2016-12-05 19:58:50 · 392 阅读 · 0 评论 -
LeetCode 15 3Sum题解
题目地址:https://leetcode.com/problems/3sum/题目:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the原创 2016-12-05 20:10:01 · 396 阅读 · 0 评论 -
LeetCode 70 Climbing Stairs题解
题目地址:https://leetcode.com/problems/climbing-stairs/题目:You are climbing a stair case. It takes n steps to reach to the top.你正在爬楼梯,这个楼梯有n个台阶。Each time you can either climb 1 or 2 steps.原创 2016-12-05 20:19:13 · 369 阅读 · 0 评论 -
LeetCode 237 Delete Node in a Linked List
题目地址:https://leetcode.com/problems/delete-node-in-a-linked-list/题目:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.写一个函数删除一个单链表中原创 2016-12-05 20:38:42 · 317 阅读 · 0 评论 -
LeetCode 104 Maximum Depth of Binary Tree题解
题目地址:https://leetcode.com/problems/maximum-depth-of-binary-tree/题目:Given a binary tree, find its maximum depth.给定一个二叉树,找出它的最大深度。The maximum depth is the number of nodes along the longe原创 2016-12-05 20:54:11 · 369 阅读 · 0 评论 -
LeetCode 141 Linked List Cycle题解
题目地址:https://leetcode.com/problems/linked-list-cycle/题目:Given a linked list, determine if it has a cycle in it.给定一个链表,找出链表中是否存在循环Follow up:Can you solve it without using extra space?原创 2016-12-05 21:00:50 · 368 阅读 · 0 评论 -
LeetCode 204 Count Primes题解
题目地址:https://leetcode.com/problems/count-primes/题目:Description:Count the number of prime numbers less than a non-negative number, n.计算比n小的非负数中素数的个数。算法设计:素数的特点:一个素数只能被自己和1整除。就是说素数不能被比原创 2016-12-05 21:15:25 · 412 阅读 · 0 评论 -
LeetCode 283 Move Zeroes题解
题目地址:https://leetcode.com/problems/move-zeroes/题目:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.给定一原创 2016-12-05 21:48:33 · 338 阅读 · 0 评论 -
LeetCode 242 Valid Anagram题解
题目:https://leetcode.com/problems/valid-anagram/题目:Given two strings s and t, write a function to determine if t is an anagram of s.给定两个字符串s和t,写出一个函数来判断t是否是s的变位词。For example,s = "anag原创 2016-12-05 14:19:39 · 427 阅读 · 0 评论 -
LeetCode 189 Rotate Array题解
题目地址:https://leetcode.com/problems/rotate-array/题目:Rotate an array of n elements to the right by k steps.将一个具有n个元素的数组向右移动k个位置。For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,原创 2016-12-05 14:08:49 · 476 阅读 · 0 评论 -
LeetCode 234 Palindrome Linked List题解
题目地址:https://leetcode.com/problems/palindrome-linked-list/题目:Given a singly linked list, determine if it is a palindrome.给定一个单链表,判断它是否是回文序列Follow up:Could you do it in O(n) time and原创 2016-11-07 20:45:12 · 381 阅读 · 0 评论 -
LeetCode 226 Invert Binary Tree题解
题目地址:https://leetcode.com/problems/invert-binary-tree/题目:Invert a binary tree.反转一颗二叉树 4 / \ 2 7 / \ / \1 3 6 9to至 4 / \ 7 2 / \ / \9 6原创 2016-11-08 12:09:50 · 512 阅读 · 0 评论 -
LeetCode 1 Two Sum题解
题目地址:https://leetcode.com/problems/two-sum/1. Two Sum难度:简单Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that e原创 2016-11-01 19:00:42 · 379 阅读 · 0 评论 -
LeetCode 6 ZigZag Conversion题解
题目地址:https://leetcode.com/problems/zigzag-conversion/题目:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern原创 2016-11-01 19:40:01 · 391 阅读 · 0 评论 -
LeetCode 27 Remove Element题解
27. Remove ElementTotal Accepted: 158828Total Submissions: 434799Difficulty: EasyContributors: AdminGiven an array and a value, remove all instances of that value in place and retu原创 2016-11-29 16:14:13 · 589 阅读 · 0 评论 -
LeetCode 58 Length of Last Word题解
题目地址:https://leetcode.com/problems/length-of-last-word/题目:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string原创 2016-12-05 11:05:04 · 351 阅读 · 0 评论 -
LeetCode 169 Majority Element题解
题目地址:https://leetcode.com/problems/majority-element/题目:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.给定一个长度为原创 2016-12-05 11:12:29 · 378 阅读 · 0 评论 -
LeetCode 121 Best Time to Buy and Sell Stock题解
题目地址:https://leetcode.com/problems/best-time-to-buy-and-sell-stock/题目:Say you have an array for which the ith element is the price of a given stock on day i.给定一个数组,第i个数组元素的值表示第i天的股价。If原创 2016-12-05 13:33:24 · 324 阅读 · 0 评论 -
LeetCode 7 Reverse Integer题解
题目地址:https://leetcode.com/problems/reverse-integer/题目:Reverse digits of an integer.按位反转一个int型数。Example1: x = 123, return 321Example2: x = -123, return -321先不考虑正负和溢出按数值来反转一个数,原创 2016-12-13 15:22:30 · 507 阅读 · 0 评论 -
LeetCode 171 Excel Sheet Column Number题解
题目地址:https://leetcode.com/problems/excel-sheet-column-number/题目:Given a column title as appear in an Excel sheet, return its corresponding column number.给定一个表,表中有列标题和其对应的列数字,返回给出的标题对应的数字。原创 2016-12-05 13:59:26 · 345 阅读 · 0 评论 -
LeetCode 136 Single Number题解
题目地址:https://leetcode.com/problems/single-number/题目:Given an array of integers, every element appears twice except for one. Find that single one.给出一个int型数组,除了一个唯一的元素只出现一次,其他元素都出现两次,找到这个唯一的原创 2016-11-05 09:37:53 · 430 阅读 · 0 评论