关于scrolltop兼容性问题 最近工作时修复topbar 渐变色问题的bug,发现 document.body.scrollTop 取值一直为0这里给出三个解决方案:解决方案1:let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;解决DTD问题htt
Average of Levels in Binary Tree 题意:求每一层的数据平均值,放到Vector里思路:层序遍历,没啥难的/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), le
Two Sum IV - Input is a BST /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas
Invert Binary Tree 反转二叉树,没仔细看题,层序遍历的思想,写完WA了,一看错误数据,尴尬的反转错了 TreeNode* invertTree(TreeNode* root) { queue q; TreeNode* newroot = root; q.push(root); while(!q.empty()){
BinaryTree C++ 最近刷LeetCode回顾二叉树相关知识,于是想自己先把二叉树的建立以及基本操作实现一遍。#include#include#include#includeusing namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x)
Find All Numbers Disappeared in an Array Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.
Single Number O(n)的时间复杂的没有想出来,看了Discuss.int singleNumber(int* nums, int numsSize) { int num = 0; for(int i=0 ;i<numsSize; i++){ num ^= nums[i]; } return num;}
Vue实现简单ToDoList 一个简单的TodoList 挂个链接点这里 注意:回车自动添加,注意先输入要做的事,再输入时间,空格隔开 <input id="todo" class="form-control" v-model="newTodo" v-on:keyup.enter="addNewTodo
Island Perimeter 勉强算一道搜索吧。。class Solution {public: int islandPerimeter(vector>& grid) { int row = grid.size(); int col = grid[0].size(); int sum = 0; for(int i=0 ;i<row ; i++){
(回顾)水池数目 &&最少步数 刷LeetCode刷到搜索,想先在nyoj上回顾两道之前做过的。 # include# include# includeusing namespace std;int n,m;int map[110][110];int fx[4][2]={0,1,0,-1,1,0,-1,0};void BFS(int x,int y){ int nx,ny; for(int
Baseball Game /** * @param {string[]} ops * @return {number} */ var calPoints = function(ops) { var arr = []; for(var i =0 ;i<ops.length ;i++){ if(ops[i] == 'D'){ var leng
Keyboard Row && Reverse Words in a String III 最近也是实在不知道该如何提升js编程水平,就用JavaScript刷LeetCode吧。发现自己有一个习惯,晚上吃完宵夜后,必须写代码,是要靠写代码助消化么?! var findWords = function(words) { var arr2 =[]; for(var i=0 ;i<words.length ;i++){ var str = word
JavaScript寄生组合继承 想讲个题外话,为什么我提到这个名字总能想到日本的一部电影《寄生兽》? exm? // 直接调用this指向window,用new不是 function Father(name,age){ this.name = name; this.age = age; } // 创建一个父类对象 var f = new Father('ilv',22);
闭包的一个小demo 点击第几个div,就打印几。 闭包 .con{ position: absolute; left: 0; right: 0; top: 0; bottom: 0; width: 10vh; height: 30vh; background-color: white; margin: aut
Merge Two Binary Trees 合并两颗二叉树,已经发现解决二叉树问题的利器就是递归~/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL),
Hamming Distance 驾照GET,最近一直在准备笔试面试,很少有时间去看科四,回家高铁上才开始看,第二天考100分过哈哈,希望可以找到一份满意的工作JS实现先说两个函数;arr.reverse() 反转数组,反转后还是数组str.split('') 将字符串转换为数组arr.join('') 将数组元素转化为字符串 var arr = ['a','b','c','d'];var str =
3列布局两边固宽中间自适应 body{margin:0;padding: 0 } .left{ width: 200px; position: absolute; height: 500px; background-color: pink; left: 0; top: 0; } .right{ width: 200px; position: absolute;
事件冒泡和捕获 图码结合,很清晰~ Hello ! document.getElementsByClassName("father")[0].addEventListener("click",function(){ alert("father"); },false); document.getEl
Margin详解 1. margin 重叠问题 因为内容比较多,总结起来不是很方便,我写了一个demo,可以方便查看:margin重叠解读2. margin 百分比计算规则 百分比margin的计算规则: 普通元素的百分比margin都是相对于容器的宽度计算 百分比margin的计算规则: 绝对定位元素的百分比margin是相对于第一个定位祖先元素(fixed/relati
如何判断两个对象是否一致 蓝标一面.. 脑子当时抽住了,只记得在java中重写equals方法,其实和在js中思路是一致的。记得方法 var aprop = Object.getOwnPropertyNames(arg1); var obj1 = { name :"ilv", age :18 }; var obj2 = { name :"ilv", age :18