
数据结构
山间有水
不想成为大佬的小菜鸟不是好菜鸟
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode中用Js实现Next Greater Element II
题目描述 Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the fir...原创 2019-03-30 08:29:05 · 190 阅读 · 0 评论 -
【剑指offer】【js版】从尾到头打印链表
题目 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。 思路 1、利用栈来解决,先把链表的每一个节点都push在数组中,那么栈顶的元素即为第一个要输出的 /*function ListNode(x){ this.val = x; this.next = null; }*/ function printListFromTailToHead(head) { va...原创 2019-05-23 15:56:58 · 160 阅读 · 0 评论 -
【剑指offer】替换空格【JavaScript】
题目描述: 请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。 第一种解法: 用正则表达式, function replaceSpace(str) { return str.replace(/\s/g,"%20") } 刚开始写return str.replace(/\s...原创 2019-05-23 14:20:36 · 148 阅读 · 0 评论 -
【剑指offer】【js】重建二叉树
输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。原创 2019-05-24 14:57:43 · 249 阅读 · 0 评论 -
数据结构---图【JavaScript】
数据结构--图 一、图的概念及实现 1、概念: 图是一种计算机中使用广泛的结构 图分为有向图和无向图 2、表示方法 1)用邻接矩阵表示无向图,邻接矩阵缺点:a.非常浪费计算机内存。b.添加和删除点很麻烦 2)邻接表表示无向图 3、邻接表的实现方式 var Graph = function(){ //存储顶点用数组表示 ...原创 2019-04-29 10:41:13 · 214 阅读 · 0 评论 -
【leetCode】【javascript】997. Find the Town Judge找到小镇的法官
题目描述: In a town, there areNpeople labelled from1toN. There is a rumor that one of these people is secretly the town judge. If thetown judge exists, then: The town judge trusts nobody. Every...原创 2019-04-29 10:28:29 · 392 阅读 · 0 评论 -
【LeetCode】【JavaScript】144. Binary Tree Preorder Traversal
题目描述: Given a binary tree, return thepreordertraversal of its nodes' values. Example: Input:[1,null,2,3] 1 \ 2 / 3 Output:[1,2,3] 翻译就是:给定一个二叉树,返回其节点值的先序遍历。 复习一下树的几种遍历 先序...原创 2019-04-26 15:21:23 · 221 阅读 · 0 评论 -
LeetCode Next Greater Element I(下一个大元素I)
题目描述: You are given two arrays(without duplicates)nums1andnums2wherenums1’s elements are subset ofnums2. Find all the next greater numbers fornums1's elements in the corresponding places ofn...原创 2019-03-29 10:49:23 · 173 阅读 · 0 评论 -
Leetcode中Minimum Add to Make Parentheses Valid用js实现
题目描述: Given a stringSof'('and')'parentheses, we add the minimum number of parentheses ('('or')', and in any positions ) so that the resulting parentheses string is valid. Formally, a parent...原创 2019-03-31 16:27:56 · 156 阅读 · 0 评论 -
【剑指offer】【JavaScript】栈的压入,弹出序列
题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。(注意:这两个序列的长度是相等的) 解析 这道题用的是栈的思想,之前在leetcode上做过几道这样的题,由于没有经常复习...原创 2019-06-28 10:29:31 · 207 阅读 · 0 评论