自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

cravingszy的博客

想要更好的东南小渣渣...

  • 博客(104)
  • 收藏
  • 关注

原创 java基础

**1.静态代码块 2.构造代码块3.构造方法的执行顺序是1>2>3;明白他们是干嘛的就理解了。 1.静态代码块:是在类的加载过程的第三步初始化的时候进行的,主要目的是给类变量赋予初始值。 2.构造代码块:是独立的,必须依附载体才能运行,Java会把构造代码块放到每种构造方法的前面,用于实例化一些共有的实例变量,减少代码量。 3.构造方法:用于实例化变量。 1是类级别的,2、3是实例级别的,

2016-09-17 16:24:22 229

原创 Word Search

Word SearchGiven a 2D board and a word, find if the word exists in the grid. 题意很简单,给你一个二维字母的数组,可以上下左右走,查找是否某个单词是否存在。同一位置的字母不可以被使用多次。代码public class Solution { static boolean[][] visited; publ

2016-06-13 16:20:39 384

原创 86. Partition List

Partition List 题意:给定一个单链表和一个x,把链表中小于x的放到前面,大于等于x的放到后面,每部分元素的原始相对位置不变。思路:其实很简单,遍历一遍链表,把小于x的都挂到head1后,把大于等于x的都放到head2后,最后再把大于等于的链表挂到小于链表的后面就可以了。代码public class Solution { public ListNode partition(Li

2016-06-07 10:34:09 306

原创 60. Permutation Sequence

全排列Permutation Sequence这题当时就没看懂 求出全排列中的第k个排列组合 代码//到现在还不是很懂 只是自己觉得这个算法很diao 所以拷贝下来以后看(也不知道会不会看 ….)public class Solution { int[] nums; boolean[] mark; public int find(int n,int k){ int

2016-06-06 10:58:21 240

原创 89. Gray Code

格雷码For example, given n = 2, return [0,1,3,2]. 代码public class Solution { public List<Integer> grayCode(int n) { List<Integer> result = new LinkedList<>(); for (int i = 0; i < 1<<n;

2016-06-02 11:07:42 195

原创 61. Rotate List

Rotate List反转列表 代码public class Solution { public ListNode rotateRight(ListNode head, int k) { if(head == null || k == 0){ return head; } ListNode p = head;

2016-06-01 10:27:09 271

原创 98. Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST).题解:代码public class Solution { List<Integer> list = new ArrayList<Integer>(); public boolean isValidBST(TreeNode root) {

2016-05-30 09:45:19 275

原创 118. Pascal's Triangle

杨辉三角代码public class Solution { public List<List<Integer>> generate(int numRows) { List<List<Integer>> res = new ArrayList<List<Integer>>(); List<Integer> row, pre = null; for

2016-05-26 10:23:35 183

原创 57. Insert Interval

Insert Interval:题意:主要考虑以下情况: 如果新区间的end < 当前区间的start,不用找下去了,把新区间插入到当前区间的前面,然后返回。 如果当前区间的end小于新区间的start,继续遍历找下一个区间。 如果当前区间和新区间发生重合,则start取两者最小的start,end取两者最大的end,生成一个新的区间。 继续遍历。 如果遍历一直到末尾也没发生区间重合,就

2016-05-23 10:34:28 197

原创 74. Search a 2D Matrix

Search a 2D Matrix代码使用二分法public class Solution { public boolean searchMatrix(int[][] matrix, int target) { int col_num = matrix[0].length; int row_num = matrix.length; int be

2016-05-20 10:27:43 198

原创 110. Balanced Binary Tree

Balanced Binary Tree判断是不是平衡二叉树代码public class Solution { private int helper(TreeNode root, int height){ if (root == null) { return height; } int leftTree =

2016-05-19 11:12:03 247

原创 56. Merge Intervals

Merge Intervals合并区间 代码第一次遇见这种Intervals 不是很能懂public class Solution { public List<Interval> merge(List<Interval> intervals) { int N = intervals.size(); Collections.sort(intervals, n

2016-05-16 10:00:52 261

原创 65. Valid Number

Valid Number此题有点没怎么懂、、、、 代码public class Solution { public boolean isNumber(String s) { s = s.trim(); boolean pointSeen = false;// 不知道为什么要定义4个 没想明白 boolean eSeen = false;

2016-05-15 10:12:40 197

原创 92. Reverse Linked List II

Reverse Linked List II代码public class Solution { public ListNode reverseBetween(ListNode head, int m, int n) { if(head == null){ return null; } ListNode dummy = n

2016-05-09 10:38:28 173

原创 101. Symmetric Tree

Symmetric Tree就是判断给定的一个树是不是中心对称树 代码public class Solution { public boolean isSymmetric(TreeNode root) { return helper(root, root); } public boolean helper(TreeNode m, TreeNode n){

2016-05-05 09:23:36 187

原创 113. Path Sum II

Path Sum II代码public class Solution { List<List<Integer>> res = new ArrayList<List<Integer>>(); public List<List<Integer>> pathSum(TreeNode root, int sum) { if(root == null){

2016-05-04 10:35:49 203

原创 112. Path Sum

Path SumGiven 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 代码public class Solution { public boolean

2016-05-04 08:52:13 188

原创 59. Spiral Matrix II

Spiral Matrix II对比上一题 此题的题意: 其实跟上一题一样 同样使用四个for循环 主要注意不要搞混变量 不然很烦代码public class Solution { public int[][] generateMatrix(int n) { int[][] ret = new int[n][n]; int top = 0,lef

2016-04-28 09:33:27 191

原创 54. Spiral Matrix

螺旋数组Spiral Matrix题意: 使用递归,一次扫描一整圈,然后用x,y记录这个圈的左上角,递归完了都+1。rows, cols记录还没扫的有多少。思想比较简单,但相当容易出错。提交了好多次。 注意:1. 扫描第一行跟最后一行要扫到底部为止,而扫描左列和右列只需要扫中间的。1 2 3 4 5 6 7 8 9 10 11 12例如以上例子: 你要 先扫1234, 然

2016-04-27 09:48:57 216

原创 《乞力马扎罗山的雪》——海明威

《乞力马扎罗山的雪》——海明威这并不是一部恢弘巨著,只是一部中篇小说。在小说临近结尾时有这样一段话:极目远眺,他看到,好像整个宇宙那样宽广无垠,在阳光中显得那么高大宏伟,而且白得令人难以置信,那就是乞力马扎罗山的山巅。于是他明白,那儿就是他现在要飞去的地方。 如果没有读过,当然不能完全理解这段话的意思。即便是读过,也未必能完全理解。男主人公哈里,他有理想,同时热恋这个世界,有点写作的才华。但成年后

2016-04-26 16:33:52 1767

原创 53. Maximum Subarray

Maximum Subarray题意:给定一个数组 找出和最大的子序列 For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has the largest sum = 6.代码其实题意很简单 使用动态规划即可public class Solution { pu

2016-04-26 09:28:48 157

原创 75. Sort Colors

Sort Colors**题意:**Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will us

2016-04-25 09:54:53 272

原创 100. Same Tree

Same TreeGiven two binary trees, write a function to check if they are equal or not.代码:public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p == null && q == null)

2016-04-22 11:15:43 177

原创 50. Pow(x, n)

Pow(x, n)\计算x的n次方代码public class Solution { public double pow(double x, int m) { double temp=x; if(m==0) return 1; temp=pow(x,m/2); if

2016-04-21 10:21:39 281

原创 49. Group Anagrams

Group AnagramsGiven an array of strings, group anagrams together.For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:[ [“ate”, “eat”,”tea”], [“nat”,”tan”], [“bat”] ]代码pub

2016-04-20 12:13:46 167

原创 java知识点2016.4.14

面试2016年4月14日南京 晴 25℃ 热 地点:华为南研所 心情:一般 任务:参加所谓的华为实习生面试(ps:同时也是自己人生的首面) …… 结果:自我认为一般,或许能拿到吧问题一:java反射机制 JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意一个方法和属性;这种动态获取的信息以及动态调用对象的方

2016-04-19 14:55:58 259

原创 48. Rotate Image

Rotate Image分析:给定一个二维数组a[n][n]顺时针旋转90度,要解决这个问题,无疑,第一件事儿就是找规律。 代码public class Solution { public void rotate(int[][] matrix) { for(int i = 0; i < matrix.length; i++){ for(int j =

2016-04-19 09:59:10 165

原创 104. Maximum Depth of Binary Tree

夏天到了 不想学习 写个简单的代码清醒一下 然后突然发现然并卵 这比装的自己都看不下去了 o(︶︿︶)o 唉 不说了 还是乖乖去改论文吧。。。Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.代码public class Solution { public int maxDepth(

2016-04-18 09:25:59 141

原创 111. Minimum Depth of Binary Tree

Minimum Depth of Binary Tree题意: Given a binary tree, find its minimum depth.代码:public class Solution { public int minDepth(TreeNode root) { if(root == null) return 0; int left = mi

2016-04-15 11:22:22 193

原创 107. Binary Tree Level Order Traversal II

Binary Tree Level Order Traversal IIFor example: Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 return its bottom-up level order traversal as: [ [15,7], [9,2

2016-04-13 09:22:03 182

原创 102. Binary Tree Level Order Traversal

Binary Tree Level Order TraversalGiven 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,#,#,15,7}

2016-04-12 14:14:49 193

原创 80. Remove Duplicates from Sorted Array II

Remove Duplicates from Sorted Array IIWhat if duplicates are allowed at most twice? For example, Given sorted array nums = [1,1,1,2,2,3], Your function should return length = 5 可以保留2次重复的代码public cl

2016-04-11 11:04:50 185

原创 82. Remove Duplicates from Sorted List II

Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example, Given 1->2->3->3->4->4-

2016-04-10 15:00:34 243

原创 83. Remove Duplicates from Sorted List

Remove Duplicates from Sorted List删除重复的 Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, retu

2016-04-10 11:11:48 182

原创 52. N-Queens II

N-Queens II、跟51. N-Queens I条件一样 只是此题求出有多少个解即可代码public class Solution { Set<Integer> cols = new HashSet<Integer>(); Set<Integer> diags1 = new HashSet<Integer>(); Set<Integer> diags2 = new H

2016-04-07 10:42:40 191

原创 51. N-Queens

N-Queens皇后问题 解题思路使用回溯法解决N皇后问题,是常见的解决方法。分N步放置皇后,由于皇后之间不能同行、同列、同斜线,所以每次放置皇后的时候,都要考虑是否与已有的皇后“冲突”,如果冲突,则改变位置,直至所有皇后放置完毕。代码

2016-04-06 17:21:09 295

原创 127. Word Ladder

Word Ladder 使用了bfs(宽度优先搜索算法) 随便看看 代码复制别人的~~~代码public class Solution { public int ladderLength(String beginWord, String endWord, Set<String> wordList) { Set<String> beginSet = new HashSet<

2016-04-05 10:47:36 290

原创 随便看看

自我理解可能许多人对内存分配上的“栈 stack ”和“堆 heap ”还不是很明白。简单的来讲, stack 上分配的内存系统自动释放, heap 上分配的内存,系统不释放,哪怕程序退出,那一块内存还是在那里。 stack 一般是静态分配内存, heap 上一般是动态分配内存。 由 malloc 系统函数分配的内存就是从堆上分配内存。从堆上分配的内存一定要自己释放。用 free 释放,不

2016-04-03 10:10:56 183

原创 95. Unique Binary Search Trees II

Unique Binary Search Trees IIGiven n = 3, your program should return all 5 unique BST’s shown below. 需要把所有的5给表示出来代码:/** * Definition for a binary tree node. * public class TreeNode { * int va

2016-03-31 16:10:28 191

原创 96. Unique Binary Search Trees

Unique Binary Search TreesGiven n = 3, there are a total of 5 unique BST’s. 给出一个n 主要计算能排出多少种不同的n代码:使用了动态规划dp :sum += dp[j] * dp[i - j - 1]; 如果给出2个节点则:sum = dp[0]*dp[1]+dp[1]*dp[0] 如果给出3个节点则:sum

2016-03-31 15:16:36 151

空空如也

空空如也

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

TA关注的人

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