- 博客(15)
- 收藏
- 关注
原创 Find the Duplicate Number
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 number, fi...
2018-01-31 20:00:40 170
原创 longest-palindromic-substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.代码如下:class Solution {publi
2018-01-27 21:33:48 123
原创 String to Integer (atoi)
题目描述 Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input
2018-01-27 15:46:03 115
原创 Reverse Integer/palindrome-number
题目1:Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions
2018-01-27 14:58:16 158
原创 palindrome-number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of conve
2018-01-27 13:28:13 74
原创 remove-nth-node-from-end-of-list
Given a linked list, remove the n th node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the ...
2018-01-23 16:50:51 156
原创 reverse-nodes-in-k-group/swap-nodes-in-pairs
题目1:reverse-nodes-in-k-group Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the
2018-01-22 21:45:18 199
原创 remove-element/remove-duplicates-from-sorted-array
题目1: 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.
2018-01-21 12:53:18 106
原创 search-insert-position/search-for-a-range/search-in-rotated-sorted-array
题目一:search-insert-position(注意:返回的是low) 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
2018-01-21 11:28:10 354
原创 sqrtx
Implementint sqrt(int x). Compute and return the square root of x.代码如下: 方法一:二分法(把mid定义成int 类型,判断条件不能用mid*mid,会溢出) 注意:返回的时highint sqrt(int x) { if(x 0) return-1; if(x==0) return
2018-01-21 11:22:40 511
原创 count_and_say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, … 1is read off as”one 1”or11. 11is read off as”two 1s”or21. 21is read off as”one 2, thenone 1”o
2018-01-21 10:49:39 134
原创 while、for、++
以下代码都是等价的,假设s是vector,对s的每个元素都赋值为0for(int i=0;i<s.size();i++) s[i]=0;int i=-1;while(++i<s.size()) s[i]=0;int i=0;while(i<s.size()) s[i++]=0;
2018-01-20 15:55:03 274
原创 strstr
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack. 若函数原型是下面的形式,则代码如下:class Solution {public: char *strStr(char *ha
2018-01-20 14:53:59 579
原创 trapping-rain-water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given[0,1,0,2,1,0,1,3,2,1,2,1],
2018-01-19 14:56:59 298
转载 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). Find two lin
2018-01-19 14:55:22 109
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人