自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(23)
  • 收藏
  • 关注

原创 阻止子元素的点击事件

问题描述: 今天在调试页面的时候遇到一个奇怪的现象,在一个父元素上面定义了一个点击事件,在父元素下面是一个一个的li标签,这上面没有任何点击事件。现象是当点击其中一个li标签时会发生一些动作。这个问题困惑了我好久,我对代码翻了好几遍,最后才确定是,点击子元素时也将会触发父元素的事件。当时我把这种现象是在父元素上定义点击事件时,实际上是在这个区域中都定义了点击事件,所以当点击子元素时,实际上也是在点

2015-09-29 20:03:02 11612

原创 [leetcode-279]Perfect Squares(java)

问题描述: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13,

2015-09-25 08:16:39 1383

原创 [leetcode-283]Move Zeroes(java)

问题描述: 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

2015-09-24 20:57:26 1191

原创 [leetcode-284]Peeking Iterator(java)

问题描述: Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation – it essentially peek() at the element that will be

2015-09-24 20:35:50 908

原创 数据结构与算法分析2.19题

问题描述: 编写一个程序求解主要元素。(何为主要元素:当某个元素在数组中出现的次数大于数组个数的一半时,该元素即为主要元素)。分析:这道题在leetcode上出现过,思想是如果将主要元素摞成一摞,然后将非主要元素摞成另一摞,因为主要元素的个数要占数组个数的一半以上,所以,非主要元素的高度一定小于主要元素的高度。那么一层一层的往下削,削到最后时还剩下的一定是主要元素。现在的困难是我们并不知道谁是主要

2015-09-23 08:59:11 1071 2

原创 数据结构与算法分析2.16

问题描述:不用递归,写出快速求幂的程序分析:快速求幂,首先构造出一个base数组,其实base[i+1] = base[i]*base[i]。然后遍历指数中的二进制数,当前位(0或者1)与对应的base数组相乘。代码如下:int getSize(int y) { int size = 0; while (y) { y = y >> 1; size++;

2015-09-22 22:41:55 697

原创 数据结构与算法分析第二章12题

问题描述: 1、求最小子序列和 2、求最小正子序列和 3、求最大子序列乘积分析: 1、求最小子序列和其实和求最大子序列和是一样一样的。 最高效的O(N)的时间复杂度算法思想是: 假设有N个元素的数组,最大子序列和为从i到j。那么想想【i,j】是否可以继续向左右扩展呢?如果不能,制约条件是什么?对于最大子序列而言,如果可以向左扩展到i’,即[i’,i],那因为[i,j]位最大子序列,所以[

2015-09-22 20:57:40 341

原创 如何根据父级元素进行相对定位

需求:首先有个父级div,若干子元素如何根据父元素的位置进行相对定位?分析:看到这个需求,我首先想到的是position:relative;然而并不能满足需求。大家可以亲手试试,为啥不能满足呢?因为position:relative是指元素相对于在文档流中位置进行移动的,而不是以父元素为基准进行移动的。那如何解决? 方法是:将父元素的position设为relative,将子元素的定位方法设为ab

2015-09-17 22:21:39 14507 2

原创 使用border-radius画圆并使字位于字的中心

需求:使用html画一个圆,圆中有个字进行说明,并且使字居中。分析:首先画圆,我第一个想法是用图片,,被骂了一顿,然后想难道用canvas画,又被骂了一顿,这才注意到CSS存在一个属性border-radius。border-radius本来是用于为div添加圆角,参数为*px或百分比,而这个值是指圆角的半径(想象一下,圆角嘛,肯定是以某个点为中心,某个点为半径来画的,而在四个角上,有了半径,实际上

2015-09-17 21:43:54 10625

原创 [leetcode-214]Shortest Palindrome(java)

问题描述: Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For ex

2015-09-09 17:09:50 447

原创 [leetcode-278]Dungeon Game(java)

问题描述: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based

2015-09-08 09:35:35 504

原创 [leetcode-174]Dungeon Game(java)

问题描述:问题描述分析:这道题第一眼看上去就是二维DP问题,但是我之前是从(0,0)到(row-1,col-1)的遍历过程,但是这样一来的话,就会在某一项出现问题,详见代码2;出现问题之后,我想那肯定要用DFS了,发现果然超时TLE。最后看了网友的答案是从后向前搜索,这样就很巧妙了避免了代码2中的问题。非常神奇。 递推关系式为:dp[i][j] = max(min(dp[i+1][j],dp[i]

2015-09-08 09:13:49 638

原创 [leetcode-149]Max Points on a Line(java)

问题描述:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.分析:这道题首先明确,如何确定在同一条直线上?那如果固定一个点,那就是通过某点与该点的向量决定,如果向量一样,那代表同一条直线。但是向量是由(x,y)决定,但是这个值不能用作hashmap的ke

2015-09-07 09:24:52 901

原创 [leetcode-275]H-Index II(java)

问题描述: What if the citations array is sorted in ascending order? Could you optimize your algorithm?分析:这道题比第一题更直观,而且可以省略排序的过程。所以直接从后向前搜索即可。这道题也可以使用二分查找的方法,如代码2 代码如下:320mspublic class Solution { pub

2015-09-06 08:57:22 776

原创 [leetcode-126]Word Ladder II(java)

问题描述:这里写链接内容分析:这道题首先要找到最短路径,最短路径是采用BFS方法,之前侯大神给我讲的时候说,为什么BFS找到的节点是最短的,因为BFS搜索过程是类似于波浪型的,一层一层荡出去,这样只要找到了结束点,这个店就一定是最短路径。 但是这道题要求把路径找出来,所以,在BFS过程中还需要记录中间路径,(实际上是构造一棵树),然后在BFS结束之后再进行DFS搜索。这里的一个trick是,在BF

2015-09-04 22:03:00 1786

原创 [leetcode-115]Distinct Subsequences(java)

问题描述: Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can b

2015-09-03 23:17:15 707

原创 [leetcode-274]H-Index(java)

问题描述: Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.According to the definition of h-index on Wikipedia: “

2015-09-03 23:03:53 2077

原创 [leetcode-99]Recover Binary Search Tree(java)

问题描述: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note: A solution using O(n) space is pretty straight forward. Could you devise

2015-09-02 15:03:44 1048

原创 [leetcode-87]Scramble String(java)

问题描述 分析:这道题实在是几多波折,看到这道题想到应该使用递归的方法,但是如何使用递归却也是煞费苦心,最开始直接递归到长度为1和长度为2时终止,小数据集时可以通过,字符串长的时候就过不了了。然后这时候,我想能不能找到两个字符串的切割点,如果能找到切割点,那么下面的for循环就可以省掉了,但是我没有找到方法,但是这时候我还是没想到可以通过剪枝来减少数据量。 剪枝的方法就是,如果待比较的字符串是s

2015-09-02 11:17:53 743

原创 [leetcode-37]Sudoku Solver(java)

问题描述: Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character ‘.’.You may assume that there will be only one unique solution. 分析:这道题使用的是回溯算法,回溯本

2015-09-01 22:20:17 1824

原创 [leetcode-32]Longest Valid Parentheses(java)

问题描述: Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, wh

2015-09-01 16:54:26 793

原创 [leetcode-4]Median of Two Sorted Arrays(c)

问题描述: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).分析:这道题非常难,单纯解这道题可以有好几种方

2015-09-01 14:30:06 255

原创 [leetcode-5]Longest Palindromic Substring(java)

问题描述: Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.分析:这道题一个很明显的方法是使用二维D

2015-09-01 09:26:31 344

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除