![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 53
小学生反弹
这个作者很懒,什么都没留下…
展开
-
83. Remove Duplicates from Sorted List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2016-03-02 19:09:55 · 268 阅读 · 0 评论 -
【leetcode】100 same tree
先对根节点进行判断是否空,之后比较是否相等,然后进而递归比较左儿子和右儿子是否相等,这里不需要进行判空。# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None#原创 2017-01-24 16:05:40 · 528 阅读 · 0 评论 -
【leetcode】412. Fizz Buzz
if else 判断语句的使用,注意熟悉不同语言语法的使用 Python版class Solution(object): def fizzBuzz(self, n): """ :type n: int :rtype: List[str] """ self=[]; for i in range(1,原创 2016-11-02 13:25:26 · 330 阅读 · 0 评论 -
【leetcode】415 Add Strings
Python代码,调了几次才AC,有点乱class Solution(object): def addStrings(self, num1, num2): """ :type num1: str :type num2: str :rtype: str """ len1 = len(num1)原创 2016-11-04 12:47:09 · 333 阅读 · 0 评论 -
Two Sum
开始想到的方法就是暴力,n2的复杂度后面网上看看资料,发现hash这个方法挺适合的class Solution {public: vector twoSum(vector& nums, int target) { unordered_mapmapping; vectorresult; for (int i=0;i<nums.size原创 2016-03-15 17:57:17 · 303 阅读 · 0 评论 -
[leetcode] 42 Trapping Rain Water
具体思路就是先计算所有柱子的面积,然后先从左到右然后从右到左把坑填满,计算一个面积用第二个面积减去第一个面积就是所求,注意各种细节。特殊情况单独讨论。原创 2016-03-25 20:21:55 · 451 阅读 · 0 评论 -
[leetcode] 27. Remove Element
哈哈,终于遇到一个水题了。class Solution {public: int removeElement(vector& nums, int val) { int index=0; for(int i=0;i { if(nums[i]!=val) {原创 2016-03-25 19:07:44 · 210 阅读 · 0 评论 -
[leetcode]4. Median of Two Sorted Arrays
leetcode中hard的题目,但是思路并不难,测试样例2000多个,要考虑到各种情况,不然就会wa具体思路:将两个排序的数组合并为一个数组(中间遇到了一些麻烦,pa,pb两个指针到头的处理,if if 不能这样使用,严格写成if else if ),最后在排好序的数组中找中位数,这时也需要判断,奇偶性,得到的结果不一样分别处理,修改了1个多小时才把2000多个样例都调试通,思维上还是不够原创 2016-03-25 14:06:06 · 256 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first five elemen原创 2016-03-03 20:06:29 · 262 阅读 · 0 评论 -
【leetcode】 39. Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number of原创 2016-03-19 20:06:21 · 410 阅读 · 0 评论 -
151. Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place in原创 2016-03-18 22:31:12 · 262 阅读 · 0 评论 -
33. Search in Rotated Sorted Array
Search in Rotated Sorted Array My Submissions Question Total Accepted: 92936 Total Submissions: 310089 Difficulty: Hard Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e原创 2016-03-03 21:05:46 · 266 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II
82. Remove Duplicates from Sorted List IIMy SubmissionsQuestionTotal Accepted: 66613 Total Submissions: 251735 Difficulty: MediumGiven a sorted linked list, delete all nodes that have duplicate number原创 2016-03-03 15:50:13 · 38992 阅读 · 0 评论 -
24. Swap Nodes in Pairs
24. Swap Nodes in PairsMy SubmissionsQuestionTotal Accepted: 84067 Total Submissions: 243002 Difficulty: MediumGiven a linked list, swap every two adjacent nodes and return its原创 2016-03-02 20:13:43 · 235 阅读 · 0 评论 -
【leetcode】458. Poor Pigs
【leetcode】458. Poor PigsThere are 1000 buckets, one and only one of them contains poison, the rest are filled with water. They all look the same. If a pig drinks that poison it will die within 15 minut原创 2017-02-02 19:59:29 · 1372 阅读 · 0 评论