- 博客(13)
- 资源 (12)
- 收藏
- 关注
原创 Implement strStr()
Description:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.问题描述在源字符串中找目标字符串,如果有,返回第一次出现的首字母索引,否则返回-1..解法一:思路:来个暴搜解法。。。Code:p
2017-02-28 21:00:00 189
原创 Find the Duplicate Number
Description:Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate
2017-02-27 21:15:27 169
原创 Search in Rotated Sorted Array
Description:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If f
2017-02-27 20:46:49 171
原创 Two Sum II - Input array is sorted
问题描述简化了的Two Sum问题,数组全部已经递增排列解法一:思路:由于已经递增排列,那么就不需要用之前的HashMap了,直接上一首一尾两个指针,根据情况移动指针就可以了Code:public class Solution { public int[] twoSum(int[] numbers, int target) { int lo = 0, hi = numbers
2017-02-27 20:37:41 174
原创 Search a 2D Matrix
Description: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
2017-02-27 20:32:44 166
原创 SSD迁移攻略
前言:由于Y480电脑实在是卡的不行,而且因为经济原因不想换电脑,所以选用SSD给电脑回血的方法,让电脑在晚年恢复一点活力。。。拆机工作:换SSD首先要做的工作就是解决硬件问题,也就是拆机。。。。 总体来说,要做的事情是把原来的机械硬盘放到光驱的位置上去(这里你需要买一个光驱托架),然后把买的SSD放到电脑的硬盘位,然后把电脑装好后开机,如果在磁盘管理中能够检测到自己的SSD,证明已经装好SS
2017-02-26 21:07:55 2737
原创 Search for a Range
Description:Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If t
2017-02-25 22:10:59 254
原创 Search Insert Position
Description: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 t
2017-02-25 21:32:57 206
原创 Validate Binary Search Tree
Description:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: 1.The left subtree of a node contains only nodes with keys less than the node
2017-02-25 21:15:13 266
原创 Find Peak Element
Description:A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks,
2017-02-24 21:34:32 248
原创 Arranging Coins
DescriptionYou have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be forme
2017-02-24 21:04:02 151
原创 Sqrt(int x) &&Sqrt(double x)
DescriptionImplement int sqrt(int x).问题描述实现求整数X的平方根函数解法一思路:核心思路是二分查找,初始左边界(left)为1,初始右边界(right)为x… 比较条件为mid与x/mid做比较。。。 如果 mid < sqrt(x) 即mid < x/mid , left = mid + 1, right不动,right为最终答案。 如果mid > sq
2017-02-24 20:55:18 796
原创 常用二分查找模板
//二分查找各种情况编写练习public class BinarySearch {//精确查找---用递归实现二分查找,精确查找目标元素的位置,假定数组递增排列,且不存在重复元素 public int bsearch1(int array[],int low,int high,int target){ if(low > high) return -1; int
2017-02-24 16:45:11 1343 1
打字母小游戏
2015-02-06
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人