- 博客(38)
- 收藏
- 关注
原创 leetcode-java-59. Spiral Matrix II
/*Given an integer n, generate a square matrix filled with elements from 1 to n^2in spiral order.For example, Given n = 3,You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7
2016-08-29 16:33:52 405
原创 leetcode-java-54. Spiral Matrix
/*Given a matrix of m x n elements (m rows, n columns), return all elementsof the matrix in spiral(螺旋) order.For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Yo
2016-08-29 16:33:05 417
原创 leetcode-java-48. Rotate Image
/*You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up: Could you do this in-place? *//*思路:本题要求不开辟新的空间,且矩阵行列相同其实就是1.先对角线做转置(左下到右上)2.在竖直
2016-08-29 14:31:36 394
原创 leetcode-java-216. Combination Sum III
/*Given a set of candidate numbers (C) and a target number (T),find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number
2016-08-28 18:08:05 442
原创 leetcode-java-40. Combination Sum II
/*Given a set of candidate numbers (C) and a target number (T),find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number
2016-08-28 18:07:26 408
原创 leetcode-java-39. Combination Sum
/*Given a set of candidate numbers (C) and a target number (T),find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number
2016-08-28 18:06:43 380
原创 leetcode-java-229. Majority Element II
/*Given an integer array of size n, find all elements that appearmore than ⌊ n/3 ⌋ times.The algorithm should run in linear time and in O(1) space. */ public class Solution { public List<Integ
2016-08-28 13:27:19 474
原创 leetcode-java-88. Merge Sorted Array
/*Given two sorted integer arrays nums1 and nums2, merge nums2 intonums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit
2016-08-28 10:10:49 997
原创 leetcode-java-189. Rotate Array
/*Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7]is rotated to [5,6,7,1,2,3,4].Note: Try to come up as many solutions as you can,
2016-08-27 15:19:31 511
原创 leetcode-java-219. Contains Duplicate II
/*Given an array of integers and an integer k, find out whetherthere are two distinct indices i and j in the array such thatnums[i] = nums[j] and the difference between i and j is at most k. *//*
2016-08-27 14:53:50 522
原创 leetcode-java-217. Contains Duplicate
/*Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every elemen
2016-08-27 13:22:41 449
原创 leetcode-java-129. Sum Root to Leaf Numbers
/*Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the total sum
2016-08-25 14:49:31 295
原创 leetcode-java-116. Populating Next Right Pointers in Each Node
/*Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If ther
2016-08-25 11:08:20 303
原创 leetcode-java-199. Binary Tree Right Side View
/*思路:从右边看,并不是指右节点--也就是每层最右边的节点,则考虑层次遍历只取最右 */ public class Solution { public List<Integer> rightSideView(TreeNode root) { List<Integer> list = new LinkedList<Integer>();
2016-08-24 14:51:46 562
原创 leetcode-java-230. Kth Smallest Element in a BST
/*Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up: What if the BST is
2016-08-24 11:20:34 360
原创 leetcode-java-111. Minimum Depth of Binary Tree
/*最小深度就是根节点到最近叶子节点的路径长度和找二叉树的最大深度类似,但是区别如下:递归终止条件:1.根节点为null时,返回02.根节点左右都null时,返回13.大返回终止条件:返回较小值+1但是需要注意的是:这样就无法保证root是否是叶子节点了, */ public class Solution { public int minDepth(TreeNode
2016-08-24 10:33:19 1010
原创 java--数据结构--8种排序算法
1.直接插入排序直接插入排序:public class SortArray { public static void main(String[] args) { int a[] = {2,4,6,1,3,8,9,7,5}; insertionSort(a); for(int i = 0;i < a.length;i++) System.out.print(a
2016-08-23 09:34:45 311
原创 leetcode-java-12. Integer to Roman
/*Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999. *//*基本字符和阿拉伯数字的对应I-1V-5X-10L-50C-100D-500M-1000(1)相同的数字连写、所表示的数等于这些数字相加得到的数、如:Ⅲ=
2016-08-22 10:54:12 248
原创 leetcode-java-279. Perfect Squares
public class Solution { public int numSquares(int n) { int[] dp = new int[n+1]; // 确保后边选min的正确 Arrays.fill(dp,Integer.MAX_VALUE); for(int i = 0;i*i <= n;i++) {
2016-08-22 10:12:34 324
原创 leetcode-java-263. Ugly Number
/*Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.For example, 6, 8 are ugly while 14 is not ugly since it
2016-08-21 19:11:58 447
原创 leetcode-java-357. Count Numbers with Unique Digits
/*Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10^n.Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100,
2016-08-21 18:53:37 459
原创 leetcode-java-367. Valid Perfect Square
/*Given a positive integer num, write a function whichreturns True if num is a perfect square else False.Example 1:Input: 16Returns: TrueExample 2:Input: 14Returns: False本题就是取平方根,然后判断得到的平方根是否是整数
2016-08-21 18:08:23 451
原创 leetcode-java-326. Power of Three
/*Given an integer, write a function to determine if it is a power of three.1.递归2.数学方法x = log(n)/log(3),x是整数就可以了--那么判断整数方法:double类型,则绝对值差小于10e-15;floor类型,则绝对值差小于10e-6 */ public class Solution {
2016-08-21 10:42:11 268
原创 leetcode-java-377. Combination Sum IV
/*Given an integer array with all positive numbers and no duplicates,find the number of possible combinations that add up to a positive integer target.nums = [1, 2, 3]target = 4The possible combina
2016-08-20 11:46:54 810
原创 leetcode-java-110. Balanced Binary Tree
/*平衡二叉树:它是一 棵空树或它的左右两个子树的高度差的绝对值不超过11.递归判断二叉树是否是平衡二叉树2.递归找二叉树高度,求高度也是用递归 递归停止条件: 递归到叶子节点时终止,即root.left==null && root.right == null时,返回1;root==null时,返回0。 */ public class Solution { pub
2016-08-17 21:14:09 658
原创 leetcode-java-257. Binary Tree Paths
/*思路:1.采用递归左子树递归找到路径(根节点+左子树)右子树递归找到路径(根节点+右子树)2.递归停止条件:递归到叶子节点时终止,即root.left==null && root.right == null时,将字符串add到result中。 */ public class Solution { public List<String> binaryTreePaths(T
2016-08-17 20:55:44 835
原创 java--数据结构--二叉树根节点到指定节点的路径
二叉树根节点到指定节点的路径这个算法是很多算法的基础。 比如说: 找节点的最近公共祖先,节点最大距离等都会用到此算法,所以要好好理解一下。
2016-08-17 13:46:24 8291 2
原创 java--数据结构--二叉树的最近公共祖先
1.若是二叉搜索树思路: 如果p,q 比root小, 则LCA必定在左子树;如果p,q 比root大, 则LCA必定在右子树;若一小一大,则LCA是root /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * Tr
2016-08-17 11:09:28 2531
原创 java--数据结构--链表
1.查找链表中点,使用两个指针ListNode searchMidNode(ListNode head) { ListNode slow = head, fast = head; while(fast && fast.next) { slow = slow.next; fast = fast.next.next; }
2016-08-16 15:29:36 268
原创 leetcode-java-108. Convert Sorted Array to Binary Search Tree
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } *//*二叉搜索树特点:小的值在左边,大的值在右边这
2016-08-16 14:45:18 935
原创 leetcode-java-107. Binary Tree Level Order Traversal II
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } *//*先层次遍历出list再让list倒置 */
2016-08-15 15:56:10 381
原创 leetcode-java-106. Construct Binary Tree from Inorder and Postorder Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ /* 1.根据postorder确定根节点 2
2016-08-15 15:55:35 226
原创 leetcode-java-105. Construct Binary Tree from Preorder and Inorder Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } *//*1.根据preorder确定根节点2.在in
2016-08-15 15:54:54 277
原创 leetcode-java-103. Binary Tree Zigzag Level Order Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } * 仿照102的思路: * 但是因为是zigzag的方法
2016-08-15 15:54:07 399
原创 leetcode-java-102. Binary Tree Level Order Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } * Given a binary tree, retur
2016-08-15 15:53:19 307
原创 leetcode-java-95. Unique Binary Search Trees II
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } *//*二叉搜索树BST:从微观上来讲,BST的每个
2016-08-15 15:52:30 1084
原创 leetcode-java-94. Binary Tree Inorder Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ /* 使用循环来解决,递归和迭代都是循环 递归
2016-08-15 15:51:48 217
转载 css-属性前的 -webkit, -moz
在CSS属性能中,我们常常能看到-webkit-,-moz-之类的前缀,这种就叫做浏览器私有前缀,是浏览器对于新CSS属性的一个提前支持。-webkit-是webkit内核的,-moz-是Firefox Gecko内核,moz代表的是Firefox的开发商Mozilla。 为什么要有私有前缀呢?因为制定HTML和CSS标准的组织W3C动作是很慢的。通常,有w3c组织成员提出一个新属性,比如
2016-08-05 14:00:53 315
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人