![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
sysu_chenhaojun
这个作者很懒,什么都没留下…
展开
-
Leetcode Week2
3.atoi()函数class Solution {public: int myAtoi(string str) { const char *s = str.c_str(); // bool int_ = true; int res=0; while(*s == ' ' && *s!='\0') ++s; if (*s == '\0') { retur原创 2017-03-05 17:26:11 · 160 阅读 · 0 评论 -
Leetcode week18
Search in Rotated Sorted ArraySuppose 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 giv原创 2017-06-20 11:19:29 · 144 阅读 · 0 评论 -
leetcode week18
Search for a RangeGiven 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原创 2017-06-20 12:13:06 · 141 阅读 · 0 评论 -
leetcode week18
Search Insert PositionGiven 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原创 2017-06-20 15:53:02 · 133 阅读 · 0 评论 -
leetcode week18
Valid SudokuDetermine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.原创 2017-06-20 16:50:12 · 173 阅读 · 0 评论 -
leetcode week18
Count and SayThe count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1"原创 2017-06-20 17:52:37 · 145 阅读 · 0 评论 -
leetcode week18
Combination SumGiven a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated原创 2017-06-20 20:30:11 · 147 阅读 · 0 评论 -
leetcode
Combination Sum IIGiven 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原创 2017-06-20 21:27:24 · 131 阅读 · 0 评论 -
leetcode
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only digits原创 2017-06-22 17:43:50 · 190 阅读 · 0 评论 -
leetcode
PermutationsGiven a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1],原创 2017-06-22 20:01:05 · 182 阅读 · 0 评论 -
Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[ [1,1,2], [1,2,1], [2,1,1原创 2017-06-22 20:49:28 · 186 阅读 · 0 评论 -
Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]class So原创 2017-06-23 11:40:33 · 174 阅读 · 0 评论 -
Leetcode Weekeek16
Divide Two Integers Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 1)考虑边界问题。 2)考虑INT_MIN与INT_MAX绝对值之间差1。原创 2017-06-11 22:32:47 · 173 阅读 · 0 评论 -
Leetcode Week16
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.class Solution {public: int strStr(string haystack,原创 2017-06-11 22:36:00 · 151 阅读 · 0 评论 -
Pow(x, n)
Implement pow(x, n).折半求解class Solution {public: double myPow(double x, int n) { double res=1.0; for(int i=n;i!=0;i/=2) { if(i%2==0) x*=x;原创 2017-06-23 12:14:09 · 242 阅读 · 0 评论 -
Leetcode Week17
Next Permutation Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearran原创 2017-06-20 01:05:24 · 180 阅读 · 0 评论 -
LeetCode Week13
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: [ "((()))", "(()())", "(())()", "()(())"原创 2017-05-21 20:08:04 · 149 阅读 · 0 评论 -
LeetCode Week13
/* 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*//**原创 2017-05-21 16:45:20 · 136 阅读 · 0 评论 -
Leetcode Week1
/*1.将Z型字符串转换成可读类型 输入 P A H NA P L S I I GY I R输出 PAHNAPLSIIGYIR例子:convert("PAYPALISHIRING", 3) 输出 "PAHNAPLSIIGYIR".*//*方法1:class Solution { public: stri原创 2017-02-26 23:42:06 · 206 阅读 · 0 评论 -
Leetcode Week3
/*5.将罗马数字转换成整数。Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路:罗马数字的基本思想是右加左减,并且左减最大只能一位。所以我们可以将所以数相加,然后再遍历一次,当前一个数比后一个数小时,从结果中减去原创 2017-03-12 13:49:22 · 133 阅读 · 0 评论 -
Leetcode Week7
/*8.最长无重复字符的子字符串,Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "a原创 2017-04-08 17:47:22 · 168 阅读 · 0 评论 -
Leetcode Week6
/*4.判断整数是否是回文(Determine whether an integer is a palindrome. Do this without extra space.),即从前面往后面读与从后面往前面读是一样的,例:12321;*//*class Solution {public: bool isPalindrome(int x) {原创 2017-04-02 20:15:50 · 216 阅读 · 0 评论 -
Leetcode Week5
/*6.找出一个字符串组的最长的公共前缀。Write a function to find the longest common prefix string amongst an array of strings.*//*class Solution {public: string longestCommonPrefix(vector& strs) {原创 2017-03-26 18:53:53 · 145 阅读 · 0 评论 -
Leetcode Week8
/* 10.最长回文子序列 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. Example: Input:原创 2017-04-15 00:54:39 · 212 阅读 · 0 评论 -
Leetcode Week10
/* 11.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 tw原创 2017-05-03 00:03:44 · 371 阅读 · 0 评论 -
Leetcode Week12
求4sum,原理同3sumGiven 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.N原创 2017-05-11 21:49:20 · 147 阅读 · 0 评论 -
Leetcode Week9
/* 9.列表式数字的相加 add two number You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single原创 2017-04-23 22:03:31 · 135 阅读 · 0 评论 -
Leetcode Week11
/*在数组中找所有3个数相加等于0的子数组*/class Solution {public: vector >* v; vector> threeSum(vector& num) { v = new vector >(); if(num.size()<3) { return *v;原创 2017-05-06 21:22:40 · 117 阅读 · 0 评论 -
Leetcode Week11
/* Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on th原创 2017-05-09 11:44:16 · 123 阅读 · 0 评论 -
Leetcode Week14
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space.原创 2017-06-05 00:56:45 · 171 阅读 · 0 评论 -
Leetcode Week15
Remove Duplicates from Sorted ArrayGiven 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 anot原创 2017-06-05 01:11:10 · 233 阅读 · 0 评论 -
Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers转载 2017-06-23 15:24:51 · 183 阅读 · 0 评论