自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 文章标题

js数组遍历的方法除了for以外的用法every对于数组的每个元素进行运行如果都返回true,最后返回true判断数组元素是不是都大于2var arr = [1, 2, 3, 4, 5, 6, 7]var res = arr.every(funtion(item, index, array){ return item > 2;});return res //res = false-f

2016-05-08 08:20:41 205

原创 leetcode #21 Merge Two Sorted Lists

这题是简单的merge 不过思路一定要清晰。public class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { if(l1==null) return l2; if(l2==null) return l1;

2015-12-25 03:11:23 238

原创 leetcode #53 Maximum Subarray

public class Solution { public int maxSubArray(int[] nums) { if(nums.length==0)return 0; int[][] table = new int[nums.length][nums.length]; for(int i=0; i<nums.length; i++){

2015-12-21 17:22:04 295

原创 leetcode #100 Maximum Depth of Binary Tree

递归实现:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution

2015-11-24 11:54:44 244

原创 leetcode #173 Binary Search Tree Iterator

这题实际上是用BST做排序的算法,应该对BST做中序遍历。 中序遍历:左子树->根节点->右子树 先遍历到的元素用一个栈存起来,方便之后用到的时候把栈中的内容还回来。 程序中的buildStack()就是一个压栈的过程,如果一个节点有左子树,就将左子树压入栈。/** * Definition for binary tree * public class TreeNode { *

2015-11-24 04:23:53 232

原创 leetcode #100 Same Tree

基本的DFS遍历/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solut

2015-11-17 15:30:40 223

原创 leetcode #63 Unique PathsII

这题和#62相仿,应该注意的是如果在应该初始化的边上有被block,那么block之后的点到终点的path数应该初始化为“0”。以及如果有一点的右方和下方均被block,那么改点也是没有到终点的路径的,应初始化为“0”public class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) {

2015-11-17 14:50:56 226

原创 leetcode #62 Unique Paths

这题比较简单是一题dp算法的题目,参考算法课week7 discussion的内容。任一点到终点的path数是其右边点和下方点到终点的path数之和。public class Solution { public int uniquePaths(int m, int n) { if(m < 1 || n < 1) return 0; if(m == 1 || n

2015-11-17 14:46:34 224

原创 leetcode #101 Symmectric tree

之前没有做过图的题目,一开始不会做,看了别人的代码才懂。 显然这题是很重要的,要好好记忆和练习。/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x)

2015-11-17 14:42:45 266

原创 leetcode #3 Longest Substring Without Repeating Characters

这题卡了很久才做出来。 主要问题在于当输入与hashmap中已有的数据相同的字母时,还要判断重复是不是发生在目前的length范围内。 如String abcbca 当最后一个a进入时,当前的length范围是“bc”,不过不加以处理,程序会误以为当前hashmap中的a是一个重复进而i-measure.get(s.charAt(i))=5-0=5 而实际上之前的a已经第二个b输入时就已经被

2015-09-18 08:37:45 288

原创 leetcode #1 TwoSum

利用hashmap搜索。hash map的key是数组中的数字,value是这个数字的index。找到对应的数字后输出其index。public class Solution { public int[] twoSum(int[] nums, int target) { Map<Integer,Integer> check = new HashMap<Integer,Inte

2015-09-17 00:50:30 269

原创 leetcode #14 LongestCommenPrefix

取到第一个单词,与第二个单词逐个单词比较,共同的就是prefix,然后再用它和第三个单词比较以此类推。public class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length==0)return ""; if(strs[0]==null||strs[0].

2015-09-17 00:47:03 239

原创 leetcode #13 Roman to Integer

Given a roman numeral, convert it to an integer.public class Solution { public int romanToInt(String s) { int outPut = 0; int mNumber = 0, dNumber = 0, cNumber = 0, lNumber = 0, xNu

2015-09-09 10:50:27 238

原创 leetcode #9 Palindrome

public class Solution { public boolean isPalindrome(int x) { boolean result=false; int digit=0,x3; if(x<0)return false; x3=x; while(x3>0){ x3=x3/

2015-09-04 01:10:31 224

原创 leetcode #8 atoi

写了好久才发现思路错了,不应该用字符串处理的。 一下代码没有通过测试,一会儿再修改,先去上课。import java.util.Scanner;public class ATOI{ public static void main(String[] args){ Scanner in = new Scanner(System.in); String inPut

2015-08-27 03:17:48 312

原创 leetcode #7 ReverseInteger

采用了一个不过脑子的算法,只是因为写的快。。。不能这样了public class Solution { public int reverse(int x) { int fin=0; boolean negative; if(x>=0)negative=false; else negative=true; x=Math.

2015-08-25 08:43:36 262

原创 leetcode #6 ZigZagConversion

ZigZagConversionThe string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H

2015-08-17 02:35:32 321

原创 leetcode #242

**leetcode #242 Valid Anagram** Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, retu

2015-08-17 02:23:04 284

空空如也

空空如也

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

TA关注的人

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