Leetcode c语言
hahachenchen789
后台开发,专注容器、k8s、云原生。
展开
-
Leetcode c语言-3Sum
Title: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 mu原创 2017-09-13 15:15:24 · 892 阅读 · 0 评论 -
Leetcode c语言-Palindrome Number
Title: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 c原创 2017-09-11 14:23:25 · 302 阅读 · 0 评论 -
Leetcode c语言-Container With Most Water
Title: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 (原创 2017-09-11 14:43:17 · 342 阅读 · 0 评论 -
Leetcode c语言-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 ca原创 2017-09-10 21:44:51 · 834 阅读 · 0 评论 -
Leetcode c语言-Implement strStr()
Title:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.这道题是实现c的库函数,strstr(str1,str2),也就是返回子字符串str2在str1中第一次原创 2017-09-19 16:02:54 · 1043 阅读 · 0 评论 -
windows+sublime text3+MINGW编译运行c
在linux下,编译运行c或者c++或python等非常简单,因为包含了gcc,g++编译器和python解释器。在windows下,可以利用MINGW安装gcc和g++编译器。MINGW:是Minimalist GNUfor Windows的缩写。MINGW提供了一键自动安装的傻瓜式安装软件,地址:https://sourceforge.net/projects/mi原创 2017-09-19 16:23:25 · 2739 阅读 · 1 评论 -
Leetcode c语言-Valid Sudoku
Title:Determine 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 '.'.A par原创 2017-09-27 23:36:40 · 595 阅读 · 0 评论 -
Leetcode c语言-Integer to Roman
Title:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.这道题目就是将数字转换成罗马数字。比较简单。Solutions:char* intToRoman(int num) { char*原创 2017-09-11 21:53:23 · 592 阅读 · 0 评论 -
Leetcode c语言-Roman to Integer
Title:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.这道题和上道题相反,将罗马数字转换成数字。两种解法:第一种,穷举法,列举出所有可能。这是所有罗马数字的整数,从1-3999. 任原创 2017-09-11 22:17:46 · 438 阅读 · 0 评论 -
Leetcode c语言-Divide Two Integers
Title:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.这道题就是实现除法,而且不能用到乘法,除法和取余。第一想法是利用加法,对于一般情况,被除数和除数都是正数,不断累加除数,直到除数原创 2017-09-19 21:38:43 · 692 阅读 · 0 评论 -
Leetcode c语言-Longest Common Prefix
Title:Write a function to find the longest common prefix string amongst an array of strings.这道题目不难,唯一要注意的是二重指针的使用,因为给了一个字符串数组,也就是一个二维数组,strs[][],对于第一个字符串,应该是strs[0],对于第一个字符串中的第一个字符,应该是strs[0][原创 2017-09-12 11:33:05 · 738 阅读 · 0 评论 -
c语言-指针和字符串
1、 字符串的表示形式在C语言中,我们可以用两种方式访问字符串(1) 用字符数组存放一个字符串,然后输出该字符串。main(){ char string[]="I love China!"; printf("%s\n", string);}(2) 用字符指针指向一个字符串。可以不定义字符数组,而定义一个字符指转载 2017-09-12 14:55:12 · 355 阅读 · 0 评论 -
LeetCode c语言- Count and Say
TiTle:The 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" or 11.原创 2017-09-28 20:55:36 · 1755 阅读 · 0 评论 -
Leetcode c语言-Next Permutation
Title: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 low原创 2017-09-20 19:24:21 · 651 阅读 · 0 评论 -
Leetcode Java-Combination Sum
Title:iven 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 number may原创 2017-09-29 15:18:20 · 486 阅读 · 0 评论 -
Leetcode c语言-Multiply Strings
Title: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 o原创 2017-10-27 16:48:31 · 935 阅读 · 0 评论 -
Leetcode c语言-Permutations
TItle:Given 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], [3,1,2]原创 2017-10-30 14:27:03 · 1252 阅读 · 0 评论 -
Leetcode c语言- Permutations II
Title: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,原创 2017-10-31 14:41:40 · 576 阅读 · 0 评论 -
Leetcode c语言-Remove Element
Title: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 in place with constant原创 2017-09-19 13:36:32 · 681 阅读 · 0 评论 -
Leetcode c语言-Remove Duplicates from Sorted Array
Title: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 i原创 2017-09-19 11:24:31 · 783 阅读 · 0 评论 -
Leetcode c语言-Swap Nodes in Pairs
Title: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 const原创 2017-09-18 23:36:43 · 737 阅读 · 0 评论 -
Leetcode c语言-3Sum Closest
Title: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原创 2017-09-13 15:32:01 · 516 阅读 · 0 评论 -
对递归算法的理解
最近刷leecode题时,碰到题目需要用到递归算法,否则基本无解。接下来结合实例谈谈本人对递归算法的理解。对递归算法的形象解释:想象用一本纯英文词典查单词,要查某一个单词的意思,翻到这个单词时,看解释,发现解释中有一个单词不认识,所以,无法明白这个要查的单词是什么意思;这时,再用这本词典(函数本身)查那个不认识的单词,又发现查的第2个单词的解释中又有一个单词不认识,那么,又原创 2017-09-13 23:09:28 · 712 阅读 · 0 评论 -
Letter c语言-Combinations of a Phone Number
Title:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.In原创 2017-09-13 23:41:16 · 1451 阅读 · 0 评论 -
Leetcode c语言-Search in Rotated Sorted Array
Title:Suppose 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 given a target value to sea原创 2017-09-24 23:59:49 · 525 阅读 · 0 评论 -
Leetcode c语言-Two Sum
Leedcode上面的题对面试很有帮助,problem上的solutions也有很多,但都是java,python,c++,js等高级语言的解答,用c的很少,Leecode也是在不久前才增加了对c的支持,接下来本人开始对problem进行c语言解答。Title:Given an array of integers, return indices of the two num原创 2017-09-08 10:15:04 · 705 阅读 · 0 评论 -
Leetcode c语言-Add Two Numbers
Title: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 digit. Add the two numbers原创 2017-09-08 10:47:50 · 413 阅读 · 0 评论 -
Leetcode c语言-4Sum
Title: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:原创 2017-09-17 13:01:05 · 420 阅读 · 1 评论 -
Leetcode c语言-Remove Nth Node From End of List
Title: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 = 2. After removing the second node from原创 2017-09-17 19:07:25 · 1045 阅读 · 0 评论 -
Leetcode c语言-Longest Substring Without Repeating Characters
Title:Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the原创 2017-09-09 11:30:08 · 548 阅读 · 0 评论 -
Leetcode c语言-Longest Palindromic Substring
Title:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid原创 2017-09-09 11:54:43 · 1315 阅读 · 0 评论 -
Leetcode c语言-Valid Parentheses
Title:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" ar原创 2017-09-17 22:46:24 · 1260 阅读 · 0 评论 -
LeetCode c语言-Search for a Range
Title:Given 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 of O(log n)原创 2017-09-26 10:29:43 · 474 阅读 · 0 评论 -
Leetcode c语言-ZigZag Conversion
Title: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 legibility)P A H原创 2017-09-10 10:20:20 · 385 阅读 · 0 评论 -
Leetcode c语言- Merge Two Sorted Lists
Title: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-09-18 13:45:15 · 1198 阅读 · 0 评论 -
LeetCode c语言-Generate Parentheses和买票找零问题
Title: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-09-18 17:35:23 · 1616 阅读 · 0 评论 -
Leetcode c语言-Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Note:The input is assumed to be a 32-bit signed integer. Your function原创 2017-09-10 21:40:14 · 226 阅读 · 0 评论 -
Leetcode c语言-Search Insert Position
Title: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 i原创 2017-09-26 23:22:57 · 711 阅读 · 0 评论 -
LeetCode c语言-Rotate Image
Title:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the i原创 2017-11-01 13:28:18 · 950 阅读 · 0 评论