![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java
文章平均质量分 79
likecool21
这个作者很懒,什么都没留下…
展开
-
LeetCode刷题笔录 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.原创 2014-04-29 15:10:20 · 528 阅读 · 0 评论 -
LeetCode刷题笔录Convert Sorted Array to Balanced Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这题可以kan'chu'lai原创 2014-05-29 06:01:16 · 783 阅读 · 0 评论 -
LeetCode刷题笔录Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2014-05-29 02:48:06 · 705 阅读 · 0 评论 -
LeetCode 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? First use a naive solution: create a new 2D mat原创 2014-07-01 23:26:45 · 482 阅读 · 0 评论 -
LeetCode刷题笔录Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2014-07-02 13:07:39 · 513 阅读 · 0 评论 -
LeetCode刷题笔录 Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length.原创 2014-05-28 05:24:33 · 577 阅读 · 0 评论 -
LeetCode刷题笔录 Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 这题不能像merge原创 2014-05-29 02:22:10 · 744 阅读 · 0 评论 -
LeetCode刷题笔录Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the原创 2014-07-21 05:08:44 · 571 阅读 · 0 评论 -
LeetCode刷题笔录Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1原创 2014-07-21 05:54:37 · 643 阅读 · 0 评论 -
LeetCode刷题笔录Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2014-07-18 03:59:38 · 627 阅读 · 0 评论 -
LeetCode刷题笔录 Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] public class Solut原创 2014-06-26 11:42:22 · 712 阅读 · 0 评论 -
LeetCode刷题笔录Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. Y原创 2014-05-29 15:30:34 · 705 阅读 · 0 评论 -
LeetCode刷题笔录Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at原创 2014-07-04 05:56:28 · 527 阅读 · 0 评论 -
LeetCode刷题笔录Binary Tree Level Order Traversal II
public class Solution { public List> levelOrderBottom(TreeNode root) { //the helper array that stores all the nodes of the previous level ArrayList previousLevel; LinkedLis原创 2014-07-04 05:26:28 · 478 阅读 · 0 评论 -
LeetCode刷题笔录 Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary原创 2014-04-24 14:14:41 · 573 阅读 · 0 评论 -
LeetCode刷题笔录 Two Sum
Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the原创 2013-08-29 12:06:57 · 12877 阅读 · 2 评论 -
LeetCode刷题笔录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 tota原创 2014-07-16 05:23:59 · 784 阅读 · 0 评论 -
LeetCode刷题笔录Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ]原创 2014-07-15 12:20:18 · 687 阅读 · 0 评论 -
LeetCode刷题笔录Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.原创 2014-07-13 00:57:09 · 1013 阅读 · 0 评论 -
LeetCode刷题笔录Path Sum
Given 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. For example: Given the below binary tree and sum原创 2014-07-13 00:36:34 · 712 阅读 · 0 评论 -
LeetCode刷题笔录Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space? A straight forward solution using O(m原创 2014-07-09 23:22:42 · 503 阅读 · 0 评论 -
LeetCode刷题笔录Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space?原创 2014-07-08 23:59:06 · 559 阅读 · 0 评论 -
LeetCode刷题笔录Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right.The first integer of each原创 2014-07-08 03:53:37 · 471 阅读 · 0 评论 -
LeetCode刷题笔录Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2014-07-08 05:10:39 · 916 阅读 · 0 评论 -
LeetCode刷题笔录Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f原创 2014-06-25 13:09:24 · 769 阅读 · 0 评论 -
LeetCode刷题笔录 Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3]. Note: Recursive soluti原创 2014-04-29 02:56:36 · 580 阅读 · 0 评论 -
LeetCode刷题笔录 Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2]. Note: Recursive solutio原创 2014-04-29 13:02:49 · 746 阅读 · 0 评论 -
LeetCode刷题笔录Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word:原创 2014-04-30 12:34:42 · 1208 阅读 · 0 评论 -
LeetCode刷题笔录 Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 随手写的一个,正常的读出每一位的数字然后反序: import java.lang.Math; public class Solution { public int revers原创 2014-02-15 13:23:49 · 808 阅读 · 0 评论 -
Leetcode刷题笔录 Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case. 想法是把这个输入的String数组的每个String元素按照其字符的ASCII码的和进行分类,每一个和对应一个ArrayList,这个数组包含所有原创 2014-02-14 16:14:51 · 741 阅读 · 0 评论 -
Reverse A Linked List
在stackoverflow上看到一个好的方案。http://stackoverflow.com/questions/354875/reversing-a-linked-list-in-java-recursively Three questions to ask: What is the reverse of null (the empty list)? null. What转载 2014-01-03 11:48:56 · 747 阅读 · 0 评论 -
Stanford Algorithms学习:Clustering 2
这是紧接上面的一道题,比较有趣 Question 2 In this question your task is again to run the clustering algorithm from lecture, but on a MUCH bigger graph. So big, in fact, that the distances (i.e., edge costs原创 2013-09-21 08:54:09 · 2448 阅读 · 0 评论 -
LeetCode 刷题笔录 Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2013-10-02 15:04:45 · 1713 阅读 · 0 评论 -
Stanford Algorithms学习:Clustering
第二周的第一个编程作业,是利用贪婪算法来实现一个clustering的问题,和ML里学的unsupervised learning差不多。 Question 1 In this programming problem and the next you'll code up the clustering algorithm from lecture for computing a原创 2013-09-18 14:42:53 · 2366 阅读 · 0 评论 -
LeetCode刷题笔录 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2013-09-01 22:48:12 · 16498 阅读 · 1 评论 -
LeetCode刷题笔录 Median Of Two Sorted Arrays
先说临界情况 A为空或者B为空 直接在非空数组中找第k大的数即可。O(1) 找最小的数,k==0的情况,也简单,比较两个数组最开头的元素,谁小就是谁 然后就是比较复杂的情况,假设寻找目标target是下标为k的数。 那么意味着在排好的数组中,在目标数之前,一共有k个比目标更小的数。 将k分成两份,一份在A的前端,一份在B的前端。这里其实将k怎么分配是一个可以讨论的问题,转载 2013-09-01 18:06:39 · 1939 阅读 · 0 评论 -
将利用acm.jar制作的java做成applet
1. manually add acm.jar each time You can add -classpath .:/usr/share/java/acm.jar to your command as in: javac -classpath .:/usr/share/java/acm.jar MyApplet.java 2. change your转载 2012-12-08 12:07:15 · 802 阅读 · 0 评论 -
LeetCode刷题笔录 Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array.原创 2014-04-17 13:12:12 · 637 阅读 · 0 评论 -
LeetCode刷题笔录Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?原创 2014-05-03 23:37:15 · 714 阅读 · 0 评论 -
LeetCode刷题笔录 Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 这题比较简单原创 2014-04-02 14:02:13 · 959 阅读 · 0 评论