![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
SyyFeng
只能愈战愈勇
展开
-
LeetCode 29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 题目大意: 两个数相除不用乘号,除号和求余运算符。 题目思路: 判断除数与被除数的正负,若为负转化为正数。 divideLong函数实现:商由1-2-4-8-16慢原创 2017-09-03 18:44:15 · 122 阅读 · 0 评论 -
Leetcode56. Merge Intervals
56. Merge Intervals(合并重复区间) Given a collection of intervals, merge all overlapping intervals. For example, Given[1,3],[2,6],[8,10],[15,18], return[1,6],[8,10],[15,18]. 题目大意: 给定·一系列区间,合并有重叠部分...原创 2017-08-25 19:04:32 · 213 阅读 · 0 评论 -
LeetCode 25. 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. k is a positive integer and is less than or equal to the length of the linked list. If the number of原创 2017-08-27 18:37:40 · 154 阅读 · 0 评论 -
LeetCode 136. Single Number
Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using原创 2017-08-27 19:24:59 · 139 阅读 · 0 评论 -
leetcode 15. 3Sum
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 of zero. Note: The solution set must not contain原创 2017-08-27 18:24:00 · 133 阅读 · 0 评论 -
LeetCode 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 two endpoints of line i is at (i, ai) and (i, 0).原创 2017-08-27 18:00:00 · 137 阅读 · 0 评论 -
Leetcode 10. 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 inpu...原创 2017-08-26 22:25:41 · 130 阅读 · 0 评论 -
Leetcode 9. Palindrome Number
题目大意:判断回文数字 注意负数不是回文数字 题目思路: 1.将给定数x倒序输出存到给定变量·,将它与x比较是否相等。 但用了额外空间。 2.不用额外空间,直接每次比较数的首位和末尾是否相等,比较后去掉首位和末尾两个数字。 AC代码: 1. bool isPalindrome(int x) { int res=0; int a=x; //x保留初始值,最后作比较...原创 2017-08-26 22:08:08 · 119 阅读 · 0 评论 -
leetcode 8. String to Integer (atoi)
Implementatoito convert a string to an integer. 题目大意:将字符转换为整数 题目要求: 1.忽略字符串前面所有的空白格。 2.从第一个字符开始转换数字,判断正负号,遇到非1-9字符则停止转换并返回已得到的值。 3.若溢出(-2147483648-2147483647),则返回相应门限值。 4.若不能合理转换返回0。 题目思路: s...原创 2017-08-26 21:19:19 · 136 阅读 · 0 评论 -
LeetCode 65. Valid Number
65. Valid Number Validate if a given string is numeric. Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>true AC代码: bool isNumber(string s) {原创 2017-08-26 20:44:35 · 176 阅读 · 0 评论 -
leetcode59. Spiral Matrix II
59.Spiral Matrix II Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order. For example, Givenn=3, You should return the following matrix: [ [ 1, 2,...原创 2017-08-25 21:23:23 · 143 阅读 · 0 评论 -
Leetcode57. Insert Interval
57. Insert Interval(插入区间) Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted accordin...原创 2017-08-25 20:51:42 · 209 阅读 · 0 评论 -
leetcode 287. 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,原创 2017-09-03 20:43:29 · 125 阅读 · 0 评论 -
leetcode 231. Power of Two
Given an integer, write a function to determine if it is a power of two. 题目大意: 判断是否是2的幂次方。 题目思路: 2的幂次方=num+num; 100=10+10; 100&011=000; 101&100=100不等于0 发现2的幂次方数的特性 n&(n-1)==0. 2的幂次方n写成二进制形式原创 2017-09-03 20:20:23 · 125 阅读 · 0 评论 -
leetcode 202. Happy Number
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equ原创 2017-09-03 20:06:45 · 128 阅读 · 0 评论 -
LeetCode· 39. Combination Sum
Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in Cwhere the candidate numbers sums to T. The same repeated number may be chosen fro原创 2017-09-03 19:47:11 · 130 阅读 · 0 评论 -
leetcode 37. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. You may assume that there will be only one unique solution. 题目大意: 填充数独。原创 2017-09-03 19:34:57 · 142 阅读 · 0 评论 -
leetcode 30. Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and原创 2017-09-03 19:19:59 · 172 阅读 · 0 评论 -
Leetcode238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O(n原创 2017-08-25 17:06:56 · 172 阅读 · 0 评论