![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
sty945
这个作者很懒,什么都没留下…
展开
-
102. Binary Tree Level Order Traversal
题目 Binary Tree Level Order Traversal层次遍历二叉树 链接 Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given binary tr原创 2018-01-06 23:00:14 · 4807 阅读 · 0 评论 -
LeetCode19. Remove Nth Node From End of List 删除链表中的倒数第n个位置的元素
前言本文使用LeetCode19. Remove Nth Node From End of List作为例子来演示,这个题目需要删除链表中的倒数第n个位置的元素代码# -*- coding: utf-8 -*-# !/usr/bin/env python# Time: 2018/6/27 23:44# Author: sty# File: 19. Remove Nt...原创 2018-07-21 11:40:57 · 5340 阅读 · 0 评论 -
192. Word Frequency 使用shell统计词频
答案cat words.txt | sed 's/ /\n/g' | sed '/^$/d' | sort | uniq -c | awk '{print $2, $1}' | sort -nrk2解释使用sed将空格替换成换行,并且删除空白行 然后使用sort进行排序然后统计出词频 最后将结果以答案要求的方式输出...原创 2018-06-18 16:51:00 · 6131 阅读 · 0 评论 -
通过前序遍历和中序遍历构建二叉树 python实现
前言通过前序遍历和中序遍历构建二叉树的原理,主要是找前序遍历根节点在中序遍历中的位置,然后将二叉树而成左子树和右子树,然后依次进行这样的操作,思路还是比较简单的代码class Node: def __init__(self, data, left, right): self.data = data self.left = left ...原创 2018-06-06 09:12:19 · 11355 阅读 · 5 评论 -
LeetCode 10. Regular Expression Matching python特性、动态规划、递归
前言本文主要提供三种不同的解法,分别是利用python的特性、动态规划、递归方法解决这个问题使用python正则属性import reclass Solution2: # @return a boolean def isMatch(self, s, p): return re.match('^' + p + '$', s) != None...原创 2018-06-05 09:14:21 · 6820 阅读 · 0 评论 -
并查集解决无向图是否有环问题
案例: 并查集原创 2018-06-04 00:17:12 · 5866 阅读 · 0 评论 -
leetcode 5. Longest Palindromic Substring 字符串中的最长回文数 逐步从O(n^2)优化至线性时间
题目解析思路一 暴力解法思路二 指针+最大长度思路3 由中间至两边找回数思路4 Manacher’s algorithm 线性时间参考文档题目链接给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为1000。示例 1:输入: "babad"输出: "bab"注意: &quot原创 2018-05-26 17:06:16 · 5998 阅读 · 0 评论 -
leetcode Longest Substring with At Most Two Distinct Characters 滑动窗口法
题目解析代码如下题目解析这一题是一道会员的题目,题目介绍如下:Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which...原创 2018-04-29 14:48:22 · 5334 阅读 · 0 评论 -
leetcode 3. Longest Substring Without Repeating Characters 最长非重复子串的长度 滑动窗口法
题目链接根据我们之前介绍的滑动窗口法的解法: 滑动窗口法详解 leetcode 438. Find All Anagrams in a String 滑动窗口法 这题,我们不难解决,使用之前的模板。可得如下解法from collections import defaultdictclass Solution: def lengthOfLongestSubstrin...原创 2018-04-29 14:17:20 · 5306 阅读 · 0 评论 -
leetcode 30. Substring with Concatenation of All Words 与所有单词相关联的字串 滑动窗口法
题目描述给定一个字符串 s 和一些长度相同的单词 words。在 s 中找出可以恰好串联 words 中所有单词的子串的起始位置。You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s)...原创 2018-05-12 22:03:47 · 5947 阅读 · 0 评论 -
leetcode 567. Permutation in String 字符串的排列 滑动窗口法
题目给定两个字符串 s1 和 s2,写一个函数来判断 s2 是否包含 s1 的排列。换句话说,第一个字符串的排列之一是第二个字符串的子串。示例1:输入: s1 = "ab" s2 = "eidbaooo"输出: True解释: s2 包含 s1 的排列之一 ("ba").示例2:输入: s1= "ab" s2 = "eidboaoo"输出: False输入的字符...原创 2018-05-12 17:26:48 · 6987 阅读 · 0 评论 -
leetcode 438. Find All Anagrams in a String 滑动窗口法
题目链接 解析主要使用滑动窗口法解题,需要好好体会的是中间的两个判断couter的用法,这里很巧妙。 如果想了解更多的滑动窗口法内容,看这里: 滑动窗口法详解代码from collections import defaultdictclass Solution: def findAnagrams(self, s, p): """ ...原创 2018-04-27 09:56:38 · 5611 阅读 · 0 评论 -
滑动窗口法详解
算法目的前言一个经典的问题代码如下总结参考资料算法目的该算法展示了如何将嵌套for循环在少数问题中转换为单个for循环,从而减少了时间的复杂性。前言一个经典的问题给一组大小为n的整数数组,计算长度为k的子数组的最大值 我们希望的结果如下Input : arr[] = {100, 200, 300, 400} k...原创 2018-04-23 09:11:52 · 47454 阅读 · 1 评论 -
互联网笔试各种主流语言在OJ上的的标准输入输出
1.求a+b的和c++#include <iostream>using namespace std;int main() { int a,b; while(cin >> a >> b)//注意while处理多个case cout << a+b << endl;}javaimpo...原创 2018-03-27 22:01:59 · 7697 阅读 · 1 评论 -
leetcode:26&80 Remove Duplicates from Sorted Array 删除数组中的重复元素
leetcode:26对数组元素进行去重,使得原数组重复元素最多保留1个 限制: 我们不可以额外分配数组,必须保持空间复杂度为O(1) 这个并不难实现:class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtyp...原创 2018-02-13 20:23:33 · 5321 阅读 · 0 评论 -
107. Binary Tree Level Order Traversal II
题目Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example: Given binary tree [3,9,20,null,null原创 2018-01-06 23:04:41 · 5352 阅读 · 0 评论 -
55道常见的计算机面试题
此图来源: http://www.chinahadoop.cn/course/1160原创 2018-08-30 20:49:29 · 11890 阅读 · 0 评论