自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(59)
  • 收藏
  • 关注

翻译 Multiply Strings

1、判断乘数或者被乘数是不是负数,如果是的话去掉 ’ - ‘if(num1[0]=='-' || num2[0]=='-') { if(num1[0]=='-') { flag*=-1; num1=num1.substr(1,num1.size()-1);

2015-05-22 14:46:40 249

翻译 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]

2015-05-22 11:52:50 269

翻译 First Missing Positive

题目: Given an unsorted integer array, find the first missing positive integer. 给定一个无序整数数组,找到的第一个失踪的正整数。 思路: 1、先用桶排序,将每个元素都放到和其位置相对应的地方[1,-1,3,4]; 2、然后再进行查找每个元素是否和其位置相对应,不对应返回i+1,否则,返回n+1; 代码:class

2015-05-22 11:15:46 229

翻译 Combination Sum II

题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combinati

2015-05-22 10:47:27 220

翻译 Combination Sum

1、典型的动态规划题 if(sum>target)return; if(sum==target){res.push_back(path);return;} for(int i= index; i<candidates.size();i++) { path.push_back(candidates[i

2015-05-22 10:43:31 259

翻译 Count and Say

题目: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2

2015-05-22 10:33:07 214

翻译 Valid Sudoku

1、判断数组中是否有重复的数,先令数组中的数为0,然后当出现的时候+1,若再次出现的时候此数组中的数>0,表示重复出现,返回false; 题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where emp

2015-05-22 09:38:51 457

翻译 Search Insert Position

题目: 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 the array.

2015-05-21 17:27:47 246

翻译 Search for a Range

题目: Given a sorted array of integers, 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 the target is not found in t

2015-05-21 16:46:39 234

翻译 Search in Rotated Sorted Array

二分方法的变种 题目: Suppose a sorted array 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 found in the array re

2015-05-19 15:08:05 198

翻译 Longest Valid Parentheses

题目: Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, whic

2015-05-19 14:42:25 213

翻译 Next Permutation

题目: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible

2015-05-19 11:54:26 247

翻译 Divide Two Integers

1、有数字判断时,先看这个数字是正是负; 2、注意最大范围2147483647,和-2147483648的判断; 3、这个题是要背住的; 题目: Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT. 思路: 1、分成两次循

2015-05-19 11:29:50 206

翻译 Implement strStr()

1、要记住这种用双重循环的查找方法;for(int i=0;i<=lengthA-lengthB;++i) { bool flag=true; for(int j=0;j<lengthB;++j) { if(haystack[i+j]!=needle[j])

2015-05-19 09:52:49 235

翻译 Remove Element

题目: 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. 如

2015-05-18 14:39:59 229

翻译 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

2015-05-18 11:40:01 175

翻译 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 end should remain as it is

2015-05-18 11:08:11 213

翻译 Swap Nodes in Pairs

1、这种倒置的问题一半都要重新再选取一个listnode,然后再加上辅助的指针,cur,ret; 2、两个结点两个结点的倒置,间隔的方法为next=ret->next->next; 题目: Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4,

2015-05-18 10:48:15 197

翻译 Merge k Sorted Lists

1、新建一个结点ListNode *head=new ListNode(0); 2、privory—queue中可以按大小进行存储的功能, priority_queue < Type, Container, Functional> 其中Type 为数据类型, Container 为保存数据的容器,Functional 为元素比较方式。 Container 必须是用数组实现的容器,比如 vect

2015-05-18 10:12:47 335

翻译 Generate Parentheses

题目: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:“((()))”, “(()())”, “(())()”, “()(())”, “()()()”

2015-05-15 11:45:56 170

翻译 Merge Two Sorted Lists

题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 思路: 1、首先判断边界条件,看是否两个都为NULL,或者是否有其中一个为NULL; 2、新建一个新的

2015-05-15 09:33:40 146

翻译 Valid Parentheses

1、Valid Parentheses 括号的匹配 题目: Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()”

2015-05-14 11:57:19 194

翻译 Remove Nth Node From End of List

1、遇到链表的问题,首先要记得判断head==NULL; 2、链表中查找某个结点时,通常用三个辅助指针来表示; 题目: Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n =

2015-05-14 11:33:17 253

翻译 4Sum

题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: Elements in a

2015-05-14 10:53:13 169

翻译 Letter Combinations of a Phone Number

1、一个简单的动态规划;lettercombination(string digits){ help(digits,i,len);}void help(string digits,int i,int len){ if(i==len) { str[len]='\0'; string temp=str; res.push_b

2015-05-14 10:13:48 208

翻译 3Sum Closest

题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exa

2015-05-14 09:37:44 149

翻译 3Sum

1、结果为vector < vector> res这样的数组时,要记得先把res进行clear; 题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum

2015-05-14 09:16:40 253

翻译 Longest Common Prefix

题目: Write a function to find the longest common prefix string amongst an array of strings. 写一个函数找到一组字符串的最长公共前缀。 思路: 1、判断数组中有无空字符串,有就返回NULL; 2、选取一个长度最小的字符串,将其和第一个字符串作对比,找出公共部分; 代码:class Solution {

2015-05-12 16:34:41 161

翻译 Roman to Integer

题目: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 思路: 我们首先来明确一下罗马数字与阿拉伯数字的换算规则:如果当前数字比前一个大,说明这一段的值应该是当前这个值减去上一个值,比如IV = 5 – 1;否则,将当前值加入到结

2015-05-12 11:56:24 243

翻译 Integer to Roman

罗马数字: 1~9: {“I”, “II”, “III”, “IV”, “V”, “VI”, “VII”, “VIII”, “IX”};10~90: {“X”, “XX”, “XXX”, “XL”, “L”, “LX”, “LXX”, “LXXX”, “XC”};100~900: {“C”, “CC”, “CCC”, “CD”, “D”, “DC”, “DCC”, “DCCC”, “CM”};10

2015-05-12 11:14:43 159

翻译 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 tw

2015-05-12 10:27:03 295

翻译 Regular Expression Matching

题目: Implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input s

2015-05-12 10:10:18 193

翻译 Palindrome Number

1、一提到数字的时候就要想到正负的判断; 2、巧妙的利用/,%来取数字的每位数; 题目: Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints: Could negative integers be palindromes? (ie

2015-05-11 10:52:21 157

翻译 String to Integer (atoi)

1、做字符串的题要注意字符串前面是否有空格等其他字符; 2、一个字符串循环结束的标志是遇到’\0’; 3、注意正负的判断; 4、注意正无穷大和负无穷大的判断; 题目: Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want

2015-05-11 10:08:31 210

原创 Reverse Integer

求一个整数的长度: int getLen(int x) { int len = 0, t = x; while (t) { t = t / 10; len += 1; } return len; }题目: Reverse digits of an integer.Example1: x = 123, retu

2015-05-11 09:51:39 217

翻译 ZigZag Conversion

找规律的题:通过从简入繁的方法发现规律,从而进行计算; 题目: The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibi

2015-05-10 21:33:19 228

翻译 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 Solut

2015-05-08 21:50:18 208

原创 动态规划方法

1、思想:避免重复的计算,先将计算过的值保存下来,如果发现有相同的步骤,直接将事先保存好的值拿出来。 动态规划其实质上是通过开辟记录表,记录已求解过的结果,当再次需要求解的时候,可以直接到那个记录表中去查找,从而避免重复计算子问题来达到降低时间复杂度的效果。实际上是一个空间换时间的算法。 动态规划,在一步选择的时候,是通过从以前求出的若干个与本步骤相关的子问题最优解中

2015-05-08 17:36:17 183

翻译 Median of Two Sorted Arrays

1、一提到中位数就要考虑数组的个数是奇数还是偶数; 2、涉及到排序数组的求和、求中位数这类的问题都要想到用二分法的思想; 题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run t

2015-05-08 15:52:57 263

翻译 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. F

2015-05-08 11:37:32 387

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除