
Leetcode
XIE_QAID
java后端
展开
-
Leetcode-19. Remove Nth Node From End of List
问题:分析单向链表的优点是插入、删除操作方便,不需要移动大量的元素,缺点在于查找没有数组方便。并且本题需要从后往前逆序查找,单项链表很难实现。解决办法:翻转链表,从而变逆序查找为顺序查找!!!因此,本题的算法复杂度为两次翻转链表的时间复杂度,加上查找第n个结点的时间复杂度,由于翻转和查找都为线性时间复杂度,所以时间复杂度为O(n);/** * Definition for singl...原创 2019-05-14 20:22:49 · 175 阅读 · 0 评论 -
Leetcode20. Valid Parentheses
问题:Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type o...原创 2019-05-15 15:32:16 · 120 阅读 · 0 评论 -
Leetcode 21. Merge Two Sorted Lists
问题:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1...原创 2019-05-15 16:31:15 · 192 阅读 · 0 评论 -
Leetcode 22. Generate Parentheses
问题:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[“((()))”,“(()())”,“(())()”,“()(())”,“()()...原创 2019-05-15 19:53:10 · 122 阅读 · 0 评论 -
使用C++语言统计文件中出现频率排前10的单词
思路:从文件中读出每一行,将字符串中的标点符号替代为空格;使用字符串输入流将字符串里的各个单词赋给单个单词变量;将单词和出现的次数构成映射放入map中;排序: 复制map到vector中,重载>运算符进行排序。代码:#include<iostream>#include<map>#include<vector>#incude<al...原创 2019-07-08 22:09:13 · 1282 阅读 · 0 评论 -
Leectcode42 Trapping Rain Water
问题描述: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.The above elevation map is represented by ...原创 2019-07-16 00:01:14 · 136 阅读 · 0 评论 -
leetcode 76. Minimum Window Substring
问题描述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).Example:Input: S = “ADOBECODEBANC”, T = “ABC”Output: “BANC”Note:I...原创 2019-07-25 15:46:50 · 102 阅读 · 0 评论 -
leetcode105. Construct Binary Tree from Preorder and Inorder Traversal
leetcode 问题链接:(https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/)分析:此题需根据先序遍历和中许遍历的特点解决。对于给定的preorder和inorder序列,先序遍历每次取出的数可以作子树的根节点;而中序遍历时,该节点的左边肯定是它的左子树,右边点肯...原创 2019-08-03 18:28:03 · 108 阅读 · 0 评论 -
leetcode78 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 nodes with keys less thanthe node’s key.T...原创 2019-08-01 17:05:33 · 169 阅读 · 0 评论