
算法与程序设计
文章平均质量分 73
ChrisTiger22
这个作者很懒,什么都没留下…
展开
-
LeetCode75
转自http://www.cnblogs.com/ganganloveu/p/3703746.htmlSort 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转载 2017-01-05 10:51:29 · 366 阅读 · 0 评论 -
LeetCode78
这道题比较简单~一次就AC了~但是我觉得求求集合子集的算法是一个很重要的子算法,还是在这里记录一下自己的思路。Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For原创 2017-01-05 23:46:59 · 419 阅读 · 0 评论 -
LeetCode 289
这道题目其实并不难,但是我在其他地方看来的一个做法却很有意思。中心思想是使用数字的高位来存储下一次的状态,用低位来存储当前的状态,这样就可以做到在原来的位置上同时存在当前的状态和下一次的状态,在全部扫描过后,将所有状态整体右移一位即可。下边是java代码的实现public class Solution { public void gameOfLife(int[][] b原创 2017-01-11 22:27:39 · 559 阅读 · 0 评论 -
LeetCode 11
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原创 2017-01-12 22:29:59 · 449 阅读 · 0 评论 -
LeetCode129(以及JAVA函数变量传递问题)
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原创 2017-02-11 12:13:34 · 531 阅读 · 0 评论 -
一道传说中的阿里面试题
前天在群里得知了一道阿里面试题,因为是别人口述,所以细节并不完整。题目大意是这样的,有一个数组,去掉其中三个数,使数组剩下的四个部分和相等,且时间复杂度为O(n)。想了很久如何使用一个循环来调度三个指针,因为在移动前两个指针的过程中,后一个指针亦必须作出反应,情况太多也太复杂。今天想到一个方法,即在数组非负的情况下,采取从两头往中间挤压的方法可以定出前后两个区间,这时候中间部分就转变成原创 2017-03-05 21:58:28 · 767 阅读 · 0 评论 -
LeetCode回溯问题合集(general solution)
全排列问题,子集问题,组合和问题都是经典的回溯问题。对于子集问题,若无重复元素情况下,可以有下面的通用解法,这个解法的关键在于:第一层递归,得出单个元素集合,第二层递归得到两个元素集合,以此类推。public List> subsets(int[] nums) { List> list = new ArrayList<>(); Arrays.sort(nums);原创 2017-03-18 22:49:55 · 1333 阅读 · 1 评论 -
LeetCode315
You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].Example原创 2017-03-13 14:38:15 · 763 阅读 · 0 评论 -
LeetCode417
Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the "Pacific ocean" touches the left and top edges of the matrix and the "Atlantic ocean" tou原创 2017-04-17 11:22:57 · 592 阅读 · 0 评论