![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 62
tsbirdman163
天空没有翅膀的痕迹而我已飞过
展开
-
LeetCode--3Sum Closest
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原创 2015-02-04 22:23:00 · 505 阅读 · 0 评论 -
LeetCode--Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For example, Given {1,2,3,4}, reorder it to原创 2015-03-07 11:50:49 · 400 阅读 · 0 评论 -
LeetCode--Reverse Nodes in k-Group
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *re原创 2015-03-06 19:48:15 · 404 阅读 · 0 评论 -
LeetCode--Swap Nodes in Pairs
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 constant space. You may not原创 2015-03-06 16:04:56 · 402 阅读 · 0 评论 -
LeetCode--Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->nullptr and k = 2, return 4->5->1->2->3->nullptr. /** * Definition for singly-原创 2015-03-06 11:24:11 · 387 阅读 · 0 评论 -
LeetCode--Remove Duplicates from Sorted List II
描述 Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1-原创 2015-03-06 09:59:44 · 398 阅读 · 0 评论 -
LeetCode--Add Two Numbers
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *ad原创 2015-03-05 11:47:42 · 474 阅读 · 0 评论 -
LeetCode--String to Integer
int myAtoi(char *str) { if(str == NULL) return 0; while(*str == ' ' && *str != NULL) str++; if( *str == NULL ) return 0; if( (*str > '9' || *str < '0')原创 2015-03-03 21:49:01 · 451 阅读 · 0 评论 -
LeetCode--Anagrams
class Solution { public: vector anagrams(vector &strs) { vector res; map> strmap; int size = strs.size(); for(auto it=strs.begin(); it!=strs.end(); it++)原创 2015-03-15 11:44:44 · 415 阅读 · 0 评论 -
LeetCode--Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2原创 2015-03-15 11:10:36 · 405 阅读 · 0 评论 -
LeetCode--Next Permutation
#include #include #include using namespace std; class Solution { public: void NextPermutation(int num[], int n); }; void Solution::NextPermutation(int num[], int n) { int change = -1; int原创 2015-03-02 20:01:48 · 415 阅读 · 0 评论 -
LeetCode--Length Of Last Word
class Solution { public: int lengthOfLastWord(const char *s) { const char *p = s; if( p == NULL) return 0; int len = 0; while( (*p) != '\0') {原创 2015-03-15 20:39:09 · 471 阅读 · 0 评论 -
LeetCode--找到两个排序数组中第k大的元素
原题目为Median of Two Sorted Arrays,这里被我改成了更为通用的名字和函数。 这是一道非常经典的题。这题更通用的形式是,给定两个已经排序好的数组,找到两者所有元 素中第 k 大的元素。 O(m + n) 的解法比较直观,直接 merge 两个数组,然后求第 k 大的元素。 不过我们仅仅需要第 k 大的元素,是不需要“排序”这么复杂的操作的。可以用一个计数器,原创 2015-02-04 22:29:12 · 8854 阅读 · 1 评论 -
Populating Next Right Pointers in Each Node II
/** * Definition for binary tree with next pointer. * struct TreeLinkNode { * int val; * TreeLinkNode *left, *right, *next; * TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL)原创 2015-05-24 20:47:23 · 639 阅读 · 0 评论