算法
文章平均质量分 82
likecool21
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 · 1991 阅读 · 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 3But the f原创 2014-06-25 13:09:24 · 834 阅读 · 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 · 565 阅读 · 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 · 519 阅读 · 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 · 526 阅读 · 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 · 583 阅读 · 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 · 968 阅读 · 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 · 532 阅读 · 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 · 618 阅读 · 0 评论 -
LeetCode刷题笔录Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.bu原创 2014-08-01 23:29:36 · 942 阅读 · 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 · 796 阅读 · 0 评论 -
LeetCode刷题笔录 Two Sum
Two SumGiven 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 · 12992 阅读 · 2 评论 -
LeetCode刷题笔录 Remove Duplicates From Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2014-06-26 00:52:55 · 536 阅读 · 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 · 762 阅读 · 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 · 16621 阅读 · 1 评论 -
Stanford Algorithms学习:Clustering
第二周的第一个编程作业,是利用贪婪算法来实现一个clustering的问题,和ML里学的unsupervised learning差不多。Question 1In this programming problem and the next you'll code up the clustering algorithm from lecture for computing a原创 2013-09-18 14:42:53 · 2463 阅读 · 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 · 1775 阅读 · 0 评论 -
Stanford Algorithms学习:Clustering 2
这是紧接上面的一道题,比较有趣Question 2In 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 · 2530 阅读 · 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 · 805 阅读 · 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 · 1019 阅读 · 0 评论 -
LeetCode刷题笔录 Pow(x,n)
Implement pow(x, n).z原创 2014-04-24 13:24:20 · 735 阅读 · 0 评论 -
LeetCode刷题笔录 Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.这题xiang原创 2014-04-25 12:34:59 · 622 阅读 · 0 评论 -
LeetCode刷题笔录 Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i原创 2014-04-11 13:39:09 · 1331 阅读 · 0 评论 -
LeetCode刷题笔录 Permutaions
public class Solution { public ArrayList> permute(int[] num) { ArrayList> result = new ArrayList>(); //start from an empty list result.add(new ArrayList()); for (转载 2014-04-12 02:42:04 · 822 阅读 · 0 评论 -
LeetCode刷题笔录 Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2014-04-27 06:42:42 · 633 阅读 · 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 · 623 阅读 · 0 评论
分享