leetcode
文章平均质量分 72
littlebirdman
让困难和挫折将肤浅懒散拖延浮躁无知愚昧被动消极悲观一点一点地从自己的性格中剔除,让自己在这些困难中重新成长起来。
展开
-
Leetcode:Pascal's Triangle
这个题挺简单,直接上代码:原创 2014-04-14 15:06:00 · 524 阅读 · 0 评论 -
Leetcode: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 L原创 2014-07-01 20:49:07 · 782 阅读 · 0 评论 -
Leetcode:Sort List 对单链表归并排序
Sort a linked list in O(n log n) time using constant space complexity.看到O(n log n)的排序算法,适合单链表的首先想到的就是归并排序/** * Definition for singly-linked list. * struct ListNode { * int val; * Lis原创 2014-07-01 21:53:42 · 916 阅读 · 0 评论 -
Leetcode:Reverse Linked List II 单链表区间范围内逆置
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the fol原创 2014-05-20 23:23:20 · 882 阅读 · 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原创 2014-04-28 18:37:03 · 999 阅读 · 0 评论 -
Leetcode:Add Binary 二进制相加
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".思路同十进制的大数相加。代码如下:class Solution {public: string addBinary(string a, str原创 2014-04-28 16:02:06 · 1189 阅读 · 0 评论 -
Leetcode:Minimum Path Sum 最小路径和
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2014-04-28 10:29:09 · 755 阅读 · 0 评论 -
Leetcode: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). Fin原创 2014-04-28 20:55:03 · 1221 阅读 · 0 评论 -
Leetcode:Remove Duplicates from Sorted List 删除单链表中重复的节点
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.思路:用扫描原创 2014-04-18 17:24:20 · 637 阅读 · 0 评论 -
Leetcode:Generate Parentheses 生成有效括号对
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:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-04-20 17:00:09 · 1097 阅读 · 0 评论 -
Leetcode:Combinations 组合
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2014-04-22 23:49:15 · 881 阅读 · 3 评论 -
Leetcode:Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non原创 2014-04-21 21:11:58 · 602 阅读 · 0 评论 -
Leetcode:Remove Duplicates from Sorted List II
不开心!链表的题看似简单,原创 2014-04-18 15:38:20 · 647 阅读 · 0 评论 -
Leetcode:Search in Rotated Sorted Array
Suppose a sorted array 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 search. If found in the array retur原创 2014-05-04 22:58:21 · 775 阅读 · 0 评论 -
Leetcode:Rotate Image 旋转图片
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?刚开始没有思路,但是自己举了几个简单的栗子才看出规律:需要一圈儿一圈儿的变换位置。有两层for循环:外原创 2014-05-01 16:08:15 · 849 阅读 · 0 评论 -
Leetcode:Subsets 求数组的所有子集
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exa原创 2014-05-02 20:25:57 · 10230 阅读 · 0 评论 -
Leetcode:Triangle 数字三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [原创 2014-04-14 17:18:45 · 1476 阅读 · 0 评论 -
Leetcode:Permutations 数组的全排列
Leetcode刷题刷到了Permutation,自己写了一下数组全排列的算法。原创 2014-04-14 10:07:51 · 2514 阅读 · 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. Y原创 2014-07-12 08:42:21 · 812 阅读 · 0 评论