LeetCode
文章平均质量分 50
此专栏用于作者对在LeetCode做题过程中对题目的记录,里面的内容基本都是原创,注入了作者对题目的理解及解题思路,并会附上相关语言的代码。此专栏可以帮助初学者提高编程水平,在IT行业特别是编程语言这一方面突飞猛进。
shen_zhu
这个作者很懒,什么都没留下…
展开
-
[leetcode]-167. Two Sum II - Input array is sorted(C语言)
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 su...原创 2018-03-11 17:18:42 · 423 阅读 · 0 评论 -
[leetcode]-1.Two Sum(C语言)
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same el...原创 2018-03-11 17:12:02 · 216 阅读 · 0 评论 -
[leetcode]-371. Sum of Two Integers(C语言)
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.实现两个数相加而不用加减运算,可以分三步来执行。1,两个数相加而不去管进位,同二进制的抑或(^)运算。 2,将前一步产生的进位...原创 2018-03-11 21:02:43 · 627 阅读 · 0 评论 -
[leetcode]-7. Reverse Integer(C语言)
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing with an envi...原创 2018-03-19 16:37:22 · 230 阅读 · 0 评论 -
[leetcode]-456. 132 Pattern(C语言)
Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak suchthat i < j < k and ai < ak < aj. Design an algorithm that takes a list of n numbers as input a...原创 2018-03-18 21:21:41 · 284 阅读 · 0 评论 -
[leetcode]-717. 1-bit and 2-bit Characters(C语言)
We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). Now given a string represented by several bits. Re...原创 2018-03-18 18:59:45 · 158 阅读 · 0 评论 -
[leetcode]-231. Power of Two(C语言)
Given an integer, write a function to determine if it is a power of two.方法一:bool isPowerOfTwo(int n) { if(n<0) return false; double s=log10(n)/log10(2); if(s-(int)s==0) ...原创 2018-03-17 19:40:56 · 456 阅读 · 0 评论 -
[leetcode]-326. Power of Three(C语言)
Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion?bool isPowerOfThree(int n) { if(n<=0) ...原创 2018-03-17 18:54:20 · 246 阅读 · 0 评论 -
[leetcode]-349. Intersection of Two Arrays(C语言)
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.The result can be in any ...原创 2018-03-15 23:04:47 · 787 阅读 · 0 评论 -
[leetcode]-27. Remove Element(C语言)
Given an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-place ...原创 2018-03-15 19:15:36 · 489 阅读 · 0 评论 -
[leetcode]-724. Find Pivot Index(C语言)
Given an array of integers nums, write a method that returns the "pivot" index of this array.We define the pivot index as the index where the sum of the numbers to the left of the index is equal to th...原创 2018-03-15 19:00:04 · 318 阅读 · 0 评论 -
[leetcode]-189. Rotate Array(C语言)
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. void rotate(int* nums, int numsSize, int k) { int ...原创 2018-03-15 18:18:06 · 1106 阅读 · 0 评论 -
[leetcode]-268. Missing Number(C语言)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.Example 1Input: [3,0,1]Output: 2Example 2Input: [9,6,4,2,3,5,7,0,1]Output: 8Not...原创 2018-03-14 23:22:54 · 594 阅读 · 0 评论 -
[leetcode]-496. Next Greater Element I(C语言)
You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2. T...原创 2018-03-14 22:24:02 · 321 阅读 · 0 评论 -
[leetcode]-503. Next Greater Element II(C语言)
Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first gre...原创 2018-03-14 22:04:18 · 189 阅读 · 0 评论 -
[leetcode]-344. Reverse String(C语言)
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".方法:将前后的两个元素依次对调。 i=0,j=n-1; i=1,j=n-2; -->j=n-i-1 p=N/2-1...原创 2018-03-14 13:12:42 · 3377 阅读 · 0 评论 -
[leetcode]-507. Perfect Number(C语言)
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself. Now, given an integer n, write a function that returns true when it is a perfect...原创 2018-03-13 20:35:15 · 314 阅读 · 0 评论 -
[leetcode]-136. Single Number(C语言)
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 extra mem...原创 2018-03-12 23:44:05 · 662 阅读 · 0 评论 -
[leetcode]-633. Sum of Square Numbers(C语言)
Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.Example 1:Input: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5Example 2:Input: 3Out...原创 2018-03-12 17:09:32 · 368 阅读 · 0 评论 -
[leetcode]-35. Search Insert Position(C语言)
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.Exam...原创 2018-03-16 18:46:20 · 602 阅读 · 0 评论