Leetcode
文章平均质量分 62
fffupeng
只要你努力微笑,命运也会惧怕你的獠牙。
展开
-
Longest Palindromic Substring最长回文
string longestPalindrome(string s) { int L = s.size(); int result = 0; string s_res = s.substr(0,1); int m, n; if(L == 0 ) { return ""; } for (int i =原创 2016-09-09 14:08:40 · 272 阅读 · 0 评论 -
Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. class Solution { public: vector res; void generate(string tmp,int L,int R) {原创 2016-11-14 22:02:25 · 207 阅读 · 0 评论 -
Valid Parentheses
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 all valid b原创 2016-10-31 12:31:58 · 208 阅读 · 0 评论 -
3Sum Closest
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 have exactly原创 2016-10-20 12:55:05 · 225 阅读 · 0 评论 -
Letter Combinations of a Phone Number
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. class Solution { publi原创 2016-10-28 15:40:18 · 179 阅读 · 0 评论 -
4sum
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. class Solution原创 2016-10-27 13:09:56 · 169 阅读 · 0 评论 -
Remove Nth Node From End of List
原本一道非常简单的题,但是晚上没有状态,想了好久。。。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solu原创 2016-10-25 22:22:31 · 220 阅读 · 0 评论 -
Merge Two Sorted Lists
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. /** * Definition for singly-linked list. * struct ListN原创 2016-11-06 10:18:13 · 202 阅读 · 0 评论 -
3sum 三个数之和为0
class Solution { public: vector> threeSum(vector& nums) { int L = nums.size(); set> res;//用于存放结果,set中不能含有相同的元素 sort(nums.begin(), nums.end()); //用stl sort排序 for (int i = 0; i < L - 2;原创 2016-10-12 16:27:21 · 610 阅读 · 0 评论 -
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). Find原创 2016-09-22 15:02:39 · 243 阅读 · 0 评论 -
Longest Common Prefix
#include "stdafx.h" #include #include #include using namespace std; string Longest_Common_Prefix(vector strs) { if (strs.empty()) return ""; int L = strs.size();//容器的长度 //寻找到最短的str的位置 int min_L原创 2016-10-11 12:58:36 · 286 阅读 · 0 评论 -
Roman to integer
#include "stdafx.h" #include #include using namespace std; int RomanToInt(string s) { int res = 0;//初始化结果 int L = s.length(); string str[4]; //string s4, s3, s2, s1; int i = 0; //千位 while (s[i原创 2016-10-10 18:59:19 · 193 阅读 · 0 评论 -
Integer to Roman
#include "stdafx.h" #include #include using namespace std; int main(int argc, _TCHAR* argv[]) { int i; cin >> i; string Roman[4][10] = { "", "I", "II", "III","IV", "V", "VI", "VII", "VIII", "IX原创 2016-10-10 13:32:12 · 298 阅读 · 0 评论 -
Add Two Numbers
class Solution { public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode *p = l1,*p1 = 0,*r1; while (p != 0&&l2!=0) { p->val = p->val + l2->val;原创 2016-09-07 13:55:33 · 241 阅读 · 0 评论 -
Longest Substring Without Repeating Characters最大字串问题
#include "stdafx.h" #include #include using namespace std; int lengthOfLongestSubstring(string s) { int pos[256]; memset(pos, -1, sizeof(pos)); int flag = -1, result = 0;//fl原创 2016-09-07 13:26:35 · 295 阅读 · 0 评论 -
palindrome_number判断int是否是回文
// palindrome_number.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include using namespace std; //如果是回文,正反应该相同的大小 bool isPalindrome(int x) { if (x return 0; int r = 0;原创 2016-09-13 14:46:27 · 396 阅读 · 0 评论 -
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 case原创 2016-09-12 16:06:02 · 256 阅读 · 0 评论 -
Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 这是一道倒序输出整数的题目,给出的例也很简单。 // Reverse_Integer.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include #i原创 2016-09-11 21:52:11 · 264 阅读 · 0 评论 -
有序二维数组查找元素
在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 class Solution { public: bool Find(int target, vector > array) { int height = array.size(); i原创 2017-04-10 08:54:22 · 415 阅读 · 0 评论