- 博客(28)
- 资源 (13)
- 收藏
- 关注
原创 丑数-以空间换时间的思想
packagecom.ytx.time_and_space;importjava.util.Scanner;/** * 以空间换时间,用一个数组保存已经找到的丑数 * 里面的数字是排好序的丑数。 * 假设数组中已经有若干个排好序的丑数,并且 * 把已有最大的丑数记作M,接下来分析如何生成 * 下一个丑数。该丑数肯定是前面某一个丑数乘以2,3 * 或者5的结果
2017-09-24 21:19:58 303
原创 丑数-直观简单的求法
packagecom.ytx.time_and_space;importjava.util.Scanner;/** * 直观简洁的求解丑数的方法 * 但是时间效率太低了,对每个数字 * 都需要判断是不是丑数,对它执行求余数和除法操作 *@authoryuantianxin * */publicclassUglyNumber_simpl
2017-09-24 21:17:49 305
原创 求旋转数组中的最小值
packagecom.ytx.Search;/** * 在旋转数组中找到最小的数字 * 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 * 输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。 * {1,2,3,4,5}-> {3,4,5,1,2} * 特例: 把排序数组的前面的0个元素搬到最后面,即排序数组本身。
2017-09-24 21:14:47 234
原创 3sum-closest
packagecom.ytx.array;importjava.util.Arrays;/** 题目: 3sum-closest * * 描述: Given an array S of n integers, find three integers in S such that the sum is * closest
2017-09-11 22:56:40 336
原创 next-permutation
packagecom.ytx.array;/** * 题目 : next-permutation * * 描述: Implement next permutation, which rearranges numbers into the lexicographically * next greater permutation of num
2017-09-11 22:52:15 200
原创 first-missing-positive
packagecom.ytx.array;importjava.util.Arrays;/** 题目:first-missing-positive * * 描述: Given an unsorted integer array, find the first missing positive integer. Fo
2017-09-11 22:51:00 360
原创 Maximum_Subarray
packagecom.ytx.dp;/** 题目描述:给定一个整数数组,如{-1,3,6,0,-9,2,-5,-1,9,3,-3},求该数组中的和最大的连续子序列 * *@authoryuantian xin * * 以下是根据之前dp算法的进一步优化,优化空间,并不需要一个数组来打表,可以用两个变量即可。 */publicclass
2017-09-11 22:48:56 179
原创 3sum
package com.ytx.hash;import java.util.ArrayList;import java.util.Arrays;/** 题目:3sum * * 描述: Given an array S of n integers, are there elements a, b, c in S such that a + b + c
2017-09-11 22:47:43 153
原创 4sum
packagecom.ytx.hash;importjava.util.ArrayList;importjava.util.Arrays;/** 题目: 4sum * * 描述: Given an array S of n integers, are there elements a, b, c, * and d in
2017-09-11 22:45:52 153
原创 two-sum
packagecom.ytx.hash;importjava.util.Arrays;importjava.util.HashMap;/** * 题目:two-sum * * 描述: Given an array of integers, find two numbers such that they add up to a specific tar
2017-09-11 22:44:06 164
原创 container-with-most-water
packagecom.ytx.array;/** 题目: container-with-most-water * * 描述: Given n non-negative integers a1 , a2 , ..., an , where each represents a point at * coordinate (i,ai
2017-09-11 22:42:27 195
原创 remove-element
packagecom.ytx.array;/** 题目:remove-element * * 描述: Given an array and a value, remove all instances of that value in place and return the new length. The order of elem
2017-09-11 22:40:24 173
原创 remove-duplicates-from-sorted-array-ii
packagecom.ytx.array;/** 题目:remove-duplicates-from-sorted-array-ii * * 描述: Follow up for "Remove Duplicates": * What if duplicates are allowed at most twice?
2017-09-11 22:38:20 221
原创 sort-colors
packagecom.ytx.array;/** 题目: sort-colors * * 描述: Given an array with n objects colored red, white or blue, sort them so that objects of the same color * are adjacen
2017-09-11 22:32:35 173
原创 spiral-matrix-ii
packagecom.ytx.array;importjava.util.ArrayList;/** 题目:spiral-matrix-ii * * 描述: Given an integer n, generate a square matrix filled with elements from 1 to n 2 in spiral order.
2017-09-04 18:02:07 230
原创 spiral-matrix
packagecom.ytx.array;importjava.util.ArrayList;importjava.util.List;/** 题目: spiral-matrix * 描述: Given a matrix of m x n elements (m rows, n columns), * return all ele
2017-09-04 18:00:43 447
原创 merge-intervals
packagecom.ytx.array;importjava.util.ArrayList;importjava.util.Collections;importjava.util.Comparator;/** 题目:merge-intervals * * 描述: Given a collection of intervals, merge all
2017-09-04 17:56:43 373
原创 remove-duplicates-from-sorted-array
packagecom.ytx.array;/** 题目:remove-duplicates-from-sorted-array * * 描述:Given a sorted array, remove the duplicates in place such that each * element appear only once and return
2017-09-03 23:38:22 283
原创 rotate-image
packagecom.ytx.array;/** 题目:rotate-image * * 描述: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise).
2017-09-03 23:36:30 213
原创 search-a-2d-matrix
packagecom.ytx.array;/** 题目: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:
2017-09-02 23:15:14 214
原创 palindrome-number
packagecom.ytx.array;/** 题目:palindrome-number * * 描述: * Determine whether an integer is apalindrome. Do this without extra space. click to show spoilers.
2017-09-02 23:11:14 138
原创 convert-sorted-array-to-binary-search-tree
packagecom.ytx.array;/** * convert-sorted-array-to-binary-search-tree * * Given an array where elements are sorted in ascending order, convert it to a height balanced BST. * *@author
2017-09-02 17:27:23 141
原创 plus-one
packagecom.ytx.array;/** * plus-one * * Given a number represented as an * array of digits, plus one to the number. * *@authoryuantian xin * 给你一个用数组表示的数,求加一之后的结果,结果还是用数组表示。 *
2017-09-02 17:26:29 215
原创 best-time-to-buy-and-sell-stock-iii
packagecom.ytx.array;/**best-time-to-buy-and-sell-stock-iii * * Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to fin
2017-09-02 17:25:19 154
原创 best-time-to-buy-and-sell-stock-ii
packagecom.ytx.array;/**best-time-to-buy-and-sell-stock-ii * * Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the max
2017-09-02 17:23:54 157
原创 best-time-to-buy-and-sell-stock
packagecom.ytx.array;/** * best-time-to-buy-and-sell-stock * * Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitte
2017-09-02 17:22:40 603
原创 Longest_consecutive_sequence
package com.ytx.array;/** * convert-sorted-array-to-binary-search-tree * * Given an array where elements are sorted in ascending order, convert it to a height balanced BST. * * @author y
2017-09-02 17:21:10 204
原创 Surrounded-Regions
packagecom.ytx.array;/**130题 * Given a 2D board containing'X'and'O', capture all regions surrounded by'X'. A region is captured byflipping all'O's into'X's in that surrounded region .
2017-09-02 17:18:10 250
WinHex19.3
2017-11-08
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人