
算法
文章平均质量分 70
emmaalways
有著編劇導演夢,癡迷歷史、電影的程序媛~
展开
-
[C++]LeetCode 8:String to Integer (atoi)(字符串转int)
Problem: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原创 2015-05-02 14:36:37 · 489 阅读 · 0 评论 -
[C++]LeetCode 5: Longest Palindromic Substring(最长回文子串)
Problem: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-05-19 16:46:54 · 657 阅读 · 0 评论 -
[C++]LeetCode 11: Container With Most Water(最大容积/最大矩形面积)
Problem: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-05-19 20:57:52 · 739 阅读 · 0 评论 -
[C++]LeetCode 28: Implement strStr() (实现strStr()函数)
Problem:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.分析:int strStr(char* haystack, char* needle) 的作用是寻找needle原创 2015-05-19 21:16:43 · 521 阅读 · 0 评论 -
[C++]LeetCode 27: Remove Element(删除数组中指定元素)
Problem:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new leng原创 2015-05-03 09:59:43 · 3468 阅读 · 0 评论 -
[C++]LeetCode 26: Remove Duplicates from Sorted Array(有序数组去重)
Problem: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 in pl原创 2015-05-02 21:43:54 · 983 阅读 · 0 评论 -
[C++]LeetCode 14: Longest Common Prefix(最长公共前缀)
Problem:Write a function to find the longest common prefix string amongst an array of strings.分析:题目非常简单明了:求一组字符串的最长前缀。指明是前缀,只需将各个字符串中字符一一比较即可。有两种比较方式:1、两两比较,再将前缀结果与下一个比较。2、依次比较第i位上所有字符原创 2015-05-02 19:19:45 · 1313 阅读 · 0 评论 -
[C++]LeetCode 9: Palindrome Number(判断整数是否是回文数)
Problem: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-05-02 15:42:47 · 2433 阅读 · 0 评论 -
[C++]LeetCode 21: Merge Two Sorted Lists(合并链表)
Problem: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.分析:归并排序的最后一个步骤。链表的归并的一个好处是当一个链表已经NULL时,只需原创 2015-05-02 21:15:53 · 491 阅读 · 0 评论 -
[C++]LeetCode 6: ZigZag Conversion(ZigZag排序)
Problem: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原创 2015-04-29 22:20:12 · 650 阅读 · 0 评论 -
[C++]LeetCode 20: Valid Parentheses(判断运算符有效性)
Problem:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are原创 2015-05-02 20:53:27 · 482 阅读 · 0 评论 -
[C++]LeetCode 7:Reverse Integer(翻转整数)
Problem:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus poin原创 2015-05-02 14:23:48 · 2926 阅读 · 0 评论 -
[C++]LeetCode 3: Longest Substring Without Repeating Characters(最长不重复子串)
Problem: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原创 2015-04-29 09:44:06 · 566 阅读 · 0 评论 -
[C++]LeetCode 19: Remove Nth Node From End of List(删除链表中倒数第n个节点)
Problem: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 the原创 2015-05-02 20:23:33 · 459 阅读 · 0 评论 -
[C++]LeetCode 1: Two Sum(无序数组求指定和)
Problem: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 tar原创 2015-04-28 20:16:29 · 1190 阅读 · 0 评论 -
[C++]LeetCode 2: Add Two Numbers(链表逆序加法)
Problem: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原创 2015-04-28 21:37:21 · 701 阅读 · 0 评论 -
[C++]LeetCode 12: Integer to Roman(将整数转换为罗马数字)
Problem:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.分析:题目的要点在于罗马数字规则,见百度百科中罗马数字词条。剩下的就是写出与规则对应的逻辑。AC Code(C++):cla原创 2015-05-19 21:08:25 · 1309 阅读 · 0 评论