Leetcode解法
文章平均质量分 69
sdu程序猿
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode Q12 : Integer to Roman
题目12: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. /****************************************************************************原创 2015-07-31 10:01:30 · 451 阅读 · 0 评论 -
Leetcode Q191:Number of 1 Bits
题目191: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation原创 2015-07-27 21:23:58 · 391 阅读 · 0 评论 -
Leetcode Q100 : Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. /** * Def原创 2015-08-13 11:00:47 · 447 阅读 · 0 评论 -
Leetcode Q88:Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add原创 2015-08-12 23:51:29 · 546 阅读 · 0 评论 -
旋转数组的最小数字
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 public : int BinarySearch(vector arr, int start, int end) { int i = 0;原创 2015-08-14 16:34:13 · 449 阅读 · 0 评论 -
Leetcode Q9: Palindrome Number
题目9: Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to st原创 2015-07-28 21:56:08 · 472 阅读 · 0 评论 -
Leetcode Q8 : String to Integer (atoi)
题目8: 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 inpu原创 2015-07-28 09:05:37 · 543 阅读 · 0 评论 -
Leetcode Q5:Longest Palindromic Substring
题目5: 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. /***************原创 2015-07-27 21:19:11 · 381 阅读 · 0 评论 -
Leetcode Q4:Median of Two Sorted Arrays
题目4: 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 time complexity should be O(log (m+n)). /******************原创 2015-07-24 11:22:49 · 610 阅读 · 0 评论 -
Leetcode Q13: Roman to Integer
题目13: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. int StrLen(char* s) { int l = 0; while (*s++ != 0) { l++;原创 2015-07-31 14:00:19 · 368 阅读 · 0 评论 -
Leetcode Q3:Longest Substring Without Repeating Characters
题目3: 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原创 2015-07-24 11:19:20 · 402 阅读 · 0 评论 -
Leetcode Q6:ZigZag Conversion
题目6: 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 N原创 2015-07-28 01:12:07 · 429 阅读 · 0 评论 -
Leetcode Q14 :Longest Common Prefix
题目14: Write a function to find the longest common prefix string amongst an array of strings. 在一组字符串中,查找最长的公共前缀,并输出。 从第一个字符,依次遍历所有字符串,如果第一个字符都相同,则添加到结果中; 直到遍历到不同字符,或某一字符串遍历结束,则输出结果。 char* max_pr原创 2015-08-02 10:48:50 · 458 阅读 · 0 评论 -
Leetcode Q15: 3Sum
题目15: 代码写的非常复杂和凌乱,需要再进行整理。 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:原创 2015-08-03 00:03:30 · 562 阅读 · 0 评论 -
Leetcode Q136: Single Number
题目136: 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原创 2015-07-28 22:22:47 · 328 阅读 · 0 评论 -
Leetcode Q1: Two Sum
题目1: Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target,原创 2015-07-24 11:14:41 · 518 阅读 · 0 评论 -
Leetcode Q11:Container With Most Water
题目11: 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,原创 2015-07-30 21:33:11 · 475 阅读 · 0 评论 -
Leetcode Q2: Add Two Numbers
题目2: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as原创 2015-07-24 11:17:40 · 438 阅读 · 0 评论 -
Leetcode Q10: Regular Expression Matching
题目10: (该题目拿到手没什么特别好的思路,从网上看的别人的解法,然后写了下自己的理解,需要常回顾) Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding原创 2015-07-29 23:10:41 · 466 阅读 · 0 评论 -
Leetcode Q7:Reverse Integer
题目7: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions to as原创 2015-07-27 10:37:25 · 601 阅读 · 0 评论
分享