- 博客(60)
- 收藏
- 关注
原创 DOM中的四个基本方法
来自《Javascript DOM编程艺术》那本书。示例代码如下: Shopping List What to buy Don't forget to buy this stuff. A tin of beans Cheese Milk alert(typeof document.getElementById("perc
2017-08-31 22:55:27 482
转载 用JavaScript实现一个网页版贪吃蛇
原文在这里:http://www.cnblogs.com/guaidaodark/p/4471565.html感谢作者。。初衷是通过看别人写的小项目学习一下js,结果发现坑还是不小。。。关于DOM,一个可供参考的网站:http://www.w3school.com.cn/js/js_htmldom.asp后续会看《JavaScript+DOM编程艺术》。。不看书还是不行。。
2017-08-30 17:40:07 2392
原创 JavaScript基础:在HTML中插入js代码
之前在数据库里学过一些简单的html,最近在学js,复习一下。。如下: This is an Example xixi haha xixihaha xixihiahia这是一个简单的网页框架,开头的用来定义类型,其后的html表明类型是html。html中使用不同的标签来区分内容,标签总是成对出现,例如:...,中间可以嵌入你需要写的内容。不同的标签作用不同,
2017-08-30 17:17:16 5074
原创 算法题中常见的C++ STL
会不定期更新一、不定长数组:这个已经用得比较熟了,暂时不写二、栈同上三、队列同上四、优先队列同样在头文件中,是一个很有用的模板类,与queue的区别在于他不是按照入队顺序出队。priority_queue通常后两个参数可以省略。五、集合
2017-08-27 23:00:11 437
原创 【Sort】350. Intersection of Two Arrays II
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 many t
2017-08-27 20:18:27 144
原创 【Sort】349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.The result
2017-08-27 20:08:20 172
原创 LeetCode Weekly Contest 47
自己还是太弱了quq,所以觉得看别人的代码来提高姿势水平比花很多时间想要有意义吧orz每道题的解答都摘自Discuss,选的都是up vote最多的:665. Non-decreasing ArrayGiven an array with n integers, your task is to check if it could become non-decreasing
2017-08-27 16:16:48 276
原创 【二叉树经典问题】145. Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut
2017-08-26 18:42:27 209
原创 【二叉树经典问题】 144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive solution is tr
2017-08-26 17:53:51 176
原创 【二叉树经典问题】94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note: Recursive solu
2017-08-26 11:41:49 139
原创 【二叉树】637. Average of Levels in Binary Tree
Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Example 1:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Explan
2017-08-26 11:26:34 194
原创 【二叉树】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,15,
2017-08-26 00:33:32 139
原创 【二叉树】617. Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tr
2017-08-26 00:10:36 254
原创 【二叉树,这题太好玩了】226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by Max Howe
2017-08-25 23:37:21 196
原创 【二叉树经典问题】110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe
2017-08-25 23:06:14 176
原创 【二叉树经典问题】100. Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.解答:凭感觉
2017-08-25 17:09:48 188
原创 【二叉树经典问题】101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3
2017-08-25 14:10:01 277
原创 【二叉树经典问题】102. 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 tree [3,9,20,null,null,15,7], 3 / \ 9 2
2017-08-24 22:17:20 138
原创 【二叉树】111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.直接1行是错的:class Solution {pub
2017-08-24 21:59:33 153
原创 【二叉树】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解答:第一想法是层次遍历,也就是广度优先:int
2017-08-24 21:22:52 150
原创 【二叉树经典问题】105. Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.做了第106题再来做这个就简单了,写递归的话思路一模一样:/** * Definition for a
2017-08-24 21:03:07 163
原创 【二叉树经典问题】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./** * Definition for a binary tree node. * struct Tr
2017-08-24 20:09:11 250
原创 【二叉树】437. Path Sum III(理解递归)
You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but it
2017-08-24 17:26:08 274
原创 【二叉树】112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum
2017-08-24 16:35:16 180
原创 【二叉树】113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \
2017-08-24 15:29:38 162
原创 【二叉树】257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]Credits:Speci
2017-08-24 10:50:09 150
原创 常用的排序算法
排序算法有很多,是一个很杂但是很重要的知识点,复习一下:笼统地来说,排序分为内部排序(Internal Sorting)和外部排序(External Sorting),我们讨论的一般是内部排序。从实现方式上讲,排序又可以分为比较排序和非比较排序,前者的时间复杂度在O(nlogn)——O(n^2)之间,后者均为O(n),在文章末尾有关于各种排序算法时间复杂度、空间复杂度、是否稳定等性质的总结。
2017-08-23 23:58:37 257
原创 200. Number of Islands(广度优先/深度优先的经典问题)
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assu
2017-08-22 19:47:27 421
原创 详解广度优先搜索(顺便学习C++的队列STL,也有一部分深搜的东西)
一、C++的队列STL广度优先搜索一般是用队列来实现的,首先学习一下C++自己带的queue:queue模板类定义在头文件中,用queue q申明一个元素类型是data_type的队列基本操作:(1)q.empty();判断队列是不是为空,若为空返回1(2)q.size();返回队列长度(3)q.push(x);入队(4)q.pop();出队(5)q.front()
2017-08-22 13:20:51 1639
原创 542. 01 Matrix(深搜/广搜/DP的题目)
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0Output:0 0 00 1 00
2017-08-21 23:20:49 283
原创 Java基础
啊,开始学Java了。。。。一、安装JDK可以在http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html下载JDK,jdk是java development kit的缩写,java程序运行必须要的工具包。注意在安装过程中第二个路径是jre的路径。还有一点就是最好不要在路径里
2017-08-20 11:23:58 190
原创 300. Longest Increasing Subsequence(DP经典问题)
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], ther
2017-08-20 11:00:56 273
原创 63. Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the
2017-08-16 00:19:32 178
原创 62. Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo
2017-08-16 00:00:14 118
原创 213. House Robber II
Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time
2017-08-15 19:16:13 120
原创 198. House Robber(哈哈哈这个简单)
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house
2017-08-14 23:35:59 174
原创 188. Best Time to Buy and Sell Stock IV(一个小结)
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.Note:You may not
2017-08-14 22:50:35 232
原创 454. 4Sum II
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l]is zero.To make problem a bit easier, all A, B, C, D have same le
2017-08-14 18:53:50 154
原创 123. Best Time to Buy and Sell Stock III(动规的好题)
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may
2017-08-14 16:15:14 163 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人