![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
翎羽飘
In order to be irreplaceable, one must always be different.
展开
-
Array, Set, Map
这三个都是用来储存一堆数据的,set和map在算法题中多用于查找,总结一下用法和区别1. arrayvar a = ['A', 'B', 'C']; 2. set:一组key的集合,没有value。key不能重复,set无重复值var s = new Set(['A', 'B', 'C']); 1)s.add('d')2)s.delete('d')3. map: 一组键值原创 2017-10-28 19:29:59 · 238 阅读 · 0 评论 -
算法系列(14) Leetcode 492. Construct the Rectangle
For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L原创 2017-12-19 21:40:40 · 180 阅读 · 0 评论 -
算法系列(8)LeetCode389
389. Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter原创 2017-11-26 21:54:00 · 166 阅读 · 0 评论 -
二叉树
1. 树:由一组以边连接的节点组成二叉树:特殊的树,子节点数不超过两个。一个父节点的两个子节点分别称为做节点和右节点。相对较小的值保存在左节点中,相对较小的值保存在右节点中。2. 实现二叉树1)node类:保存数据、和其他节点的链接2)BST类: function Node(data, left, right) { this.data = data; t原创 2017-12-05 23:08:38 · 376 阅读 · 0 评论 -
图
1. 创建:1)创建图类2)创建顶点类3)创建边类function Graph(v) { this.vertices = v; this.edges = 0; this.adj = []; for (var i = 0; i < this.vertices; ++i) { this.adj[i] = []; this.ad原创 2017-12-06 10:18:24 · 123 阅读 · 0 评论 -
动态规划问题和贪心算法
啊啊啊,刺猬书的动态规划看的一知半解,,怎么用!!!晕死了。。稍微做一下记录,后面再看看会不会有更好的理解呢~1. 什么是动态规划?与递归相反,从底部解决问题,将所有的小问题解决掉,然后合并成一个整体解决方案,从而解决掉整个大问题。(感觉就是针对数组的各种操作,用数组替代递归的操作,因为递归每次都要算一遍,耗时)1)斐波那契数列function dynFib(n) { va原创 2017-12-07 12:06:25 · 341 阅读 · 0 评论 -
算法系列(15)LeetCode 171
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...原创 2017-12-25 21:17:39 · 169 阅读 · 0 评论 -
算法系列(16)Leetcode 387 First Unique Character in a String
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.思路:若要查找整个字符串是原创 2017-12-26 09:20:43 · 143 阅读 · 0 评论 -
算法系列(17) Leetcode 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.思路:这个是在网上找的答案,所以归纳为转载,有关二叉树真的不会。。。转载 2017-12-26 20:12:12 · 131 阅读 · 0 评论 -
算法系列(18) Leetcode 496. Next Greater Element I
You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums原创 2018-01-03 22:41:16 · 230 阅读 · 0 评论 -
算法系列(19)Leetcode 344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh"./** * @param {string} s * @return {string} */var reverseString = f原创 2018-01-07 19:36:15 · 145 阅读 · 0 评论 -
算法系列(13) Leetcode 169 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.You may assume that the array is non-empty and the majority element原创 2017-12-19 20:27:51 · 216 阅读 · 0 评论 -
算法系列(12)LeetCode292 Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2017-12-02 10:17:39 · 180 阅读 · 0 评论 -
算法刷题系列(1)leetcode349
最近开始刷leetcode算法啦,但是作为一个研究生转专业保研的宝宝,算法实在渣渣,c++也不是很擅长,就刷一下js的版本吧,答案又少,在这记录下来自己刷过题目的答案吧,但是肯定不是最好的办法原创 2017-10-29 10:50:05 · 265 阅读 · 0 评论 -
算法系列(2)leetcode283
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.For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2017-10-29 10:55:31 · 156 阅读 · 0 评论 -
算法系列(3)leetcode27
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.原创 2017-10-29 10:57:21 · 256 阅读 · 0 评论 -
算法系列(4) leetcode26
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2017-10-29 10:59:17 · 216 阅读 · 0 评论 -
算法系列(5) leetcode350
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as ma原创 2017-10-29 12:18:43 · 285 阅读 · 0 评论 -
算法系列(6) leetcode1
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 not use the sam原创 2017-10-30 19:59:12 · 171 阅读 · 0 评论 -
算法系列(7)leetcode 206
Reverse a singly linked list./** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } *//** * @param {ListNode} head * @return {原创 2017-11-11 16:57:00 · 166 阅读 · 0 评论 -
算法系列(9) LeetCode256
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has o原创 2017-11-28 09:49:10 · 464 阅读 · 0 评论 -
算法系列(10)LeetCode520 Detect Capital
嘿嘿,刷题刷个520~~Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:原创 2017-11-28 10:01:47 · 175 阅读 · 0 评论 -
算法系列(11)LeetCode136 Single Number
决定以后刷题一定要记下来整个思路,方便以后看原创 2017-12-02 09:58:04 · 125 阅读 · 0 评论 -
算法系列(20) Leetcode 575. Distribute Candies
Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute t原创 2018-01-07 20:49:20 · 211 阅读 · 0 评论