- 博客(13)
- 收藏
- 关注
原创 [python]Leetcode 647. Palindromic Substrings Medium
题目描述 Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are counted as different substrings even they cons...
2019-02-14 23:18:38
294
原创 [Python]Leetcode 5. Longest Palindromic Substring
题目描述 Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: “babad” Output: “bab” Note: “aba” is also a valid answer. Exa...
2019-02-14 23:07:39
182
原创 [python] Leetcode 7. Reverse Integer
题目描述 Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note: Assume we are dealing wit...
2019-01-27 17:41:05
211
原创 [python] Leetcode 3. Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. Example 1: Input: “abcabcbb” Output: 3 Explanation: The answer is “abc”, with the length of 3. Example 2: In...
2019-01-27 12:56:54
184
原创 [Python]Leetcode 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 each input would have exactly one solution, and you may no...
2019-01-27 02:03:12
153
原创 [python] LeetCode84. Largest Rectangle in Histogram
题目描述 Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. 思路 用一个栈,每找到一个局部峰值时,触发while循环,向前遍历得最大值 ...
2019-01-13 23:04:21
135
原创 [python] LeetCode 53. Maximum Subarray
题目描述 原题链接地址:https://leetcode.com/problems/maximum-subarray/description/ Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return ...
2019-01-12 11:58:30
118
原创 (C++版)剑指offer——对称的二叉树
题目描述 请实现一个函数,用来判断一颗二叉树是不是对称的。注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的。 思路 本文分递归与非递归两种方式实现 /*递归 思路:首先根节点以及其左右子树,左子树的左子树和右子树的右子树相同 * 左子树的右子树和右子树的左子树相同即可 */ class Solution { public: bool Compare(TreeNode* le...
2019-01-08 10:51:21
343
原创 (C++版)剑指offer——机器人的运动范围
题目描述 地上有一个m行和n列的方格。一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和大于k的格子。 例如,当k为18时,机器人能够进入方格(35,37),因为3+5+3+7 = 18。但是,它不能进入方格(35,38),因为3+5+3+8 = 19。请问该机器人能够达到多少个格子? 思路 回溯法,DFS 代码 int movx...
2019-01-07 21:22:11
423
原创 [python版]剑指offer --滑动窗口最大值
题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值。例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6,6,6,5}; 针对数组{2,3,4,2,6,2,5,1}的滑动窗口有以下6个: {[2,3,4],2,6,2,5,1}, {2,[3,4,2],6,2,5,1}, {2,3,[4,2,6],2,5...
2018-12-15 11:59:57
160
原创 [python版]Leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
题目 中文:根据中序后序构建二叉树 英文原题: Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. For example, given inorder = [9,3,15,...
2018-12-11 12:29:43
469
原创 [python版]剑指offer -- 重建二叉树
题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。 代码实现 # -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): #...
2018-12-11 11:46:52
220
原创 [python版]剑指offer -- 二叉搜索树的第k大结点
剑指offer(python版)-- 二叉搜索树的第k大结点 思路 二叉搜索树按照中序遍历的顺序打印出来正好就是排序好的顺序。 所以,按照中序遍历的第k个结点就是结果。 注:本题返回的是结点,而不是结点值。 实现代码 # -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val =...
2018-12-11 00:23:12
299
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人