随笔分类 -  leetcode解题报告

leetcode : Basic Calculator II
摘要:实现一个简单的计算器,在llvm和wiki上看见的算法 阅读全文

posted @ 2016-07-28 21:58 远近闻名的学渣

leetcode : Product of Array Except Self
摘要:Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except  阅读全文

posted @ 2016-03-28 11:58 远近闻名的学渣 阅读(122) 评论(0) 推荐(0)

leetcode :Spiral Matrix
摘要:题目很简单,就是花式拐弯遍历一个矩阵。 既然题目花式拐弯遍历矩阵,那我们就来一个花式漂移完成拐弯瞬间爆炸的解法: 1,定义四个移动操作,goLeft,goRight,goUp,goDown 2,定义四个边界,up,down,left, right,当goLeft走到头的时候,将down边界往上移一行 阅读全文

posted @ 2016-03-27 15:57 远近闻名的学渣

DFS算法的循环结束条件
摘要:写DFS算法时,最好在函数入口处判断边界条件与结束条件,如 void dfs () { check_bound(); check_end(); dfs(); } 这样的好处有: 1,写算法的时候,首先是要考虑空输入的,如vector<int>{}这样的初始输入,所以要么在dfs之前判断,要么在dfs 阅读全文

posted @ 2016-03-26 22:12 远近闻名的学渣

leetcode : Single Number
摘要:这个题一个有三道:Single Number i:给n个整数,其中有一个数只出现了一次,其他的数都出现了两次,求那个single number,这个很简单,把所有的数字做一下异或,得到的结果就是那个single dog。Single Number ii:给n个整数,其中所有的整数都出现了三次,除了一... 阅读全文

posted @ 2015-09-30 22:19 远近闻名的学渣

leetcode : Peeking Iterator
摘要:Given an Iterator class interface with methods:next()andhasNext(), design and implement a PeekingIterator that support thepeek()operation -- it essent... 阅读全文

posted @ 2015-09-30 21:20 远近闻名的学渣

leetcode : Kth Smallest Element in a BST
摘要:Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST's tota... 阅读全文

posted @ 2015-08-10 13:23 远近闻名的学渣 阅读(141) 评论(0) 推荐(0)

leetcode :Factorial Trailing Zeroes
摘要:Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.大致意思给一个n,判断n的阶乘后面有几个0。从1数到n,最... 阅读全文

posted @ 2015-07-15 16:06 远近闻名的学渣 阅读(114) 评论(0) 推荐(0)

leetcode:Implement strStr() & KMP 算法
摘要:# leetcode:Implement strStr() & KMP 算法---## 问题描述实现strstr(),即字符串匹配。使用KMP算法解决。但是其实暴力求解也跟KMP算法的速度是相差无几的,因为目标串太短了---## KMP算法与自动机---在编译原理的书上看见KMP算法的一种解释,将目... 阅读全文

posted @ 2015-07-02 19:05 远近闻名的学渣 阅读(224) 评论(0) 推荐(0)

leetcode :4Sum
摘要:Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of ... 阅读全文

posted @ 2015-02-14 09:41 远近闻名的学渣 阅读(172) 评论(0) 推荐(0)

leetcode : Longest Palindromic Substring
摘要:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest pa... 阅读全文

posted @ 2014-12-23 21:28 远近闻名的学渣

leetcode : Trapping Rain Water
摘要:Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.Fo... 阅读全文

posted @ 2014-12-22 19:55 远近闻名的学渣 阅读(157) 评论(0) 推荐(0)

leetcode : Reverse Nodes in k-Group
摘要:Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthen left-o... 阅读全文

posted @ 2014-12-18 14:52 远近闻名的学渣 阅读(109) 评论(0) 推荐(0)

leetcode : Permutations I&II
摘要:I:Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[... 阅读全文

posted @ 2014-12-17 19:32 远近闻名的学渣 阅读(170) 评论(0) 推荐(0)

leetcode : Merge K sorted Lists
摘要:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目的重点在与分析描述复杂度。。。一看到多路归并就想到外部排序结果果断二了个逼。两种思路,一种是建个胜者树或... 阅读全文

posted @ 2014-12-14 22:35 远近闻名的学渣 阅读(295) 评论(0) 推荐(0)

leetcode : First Missing Positive
摘要:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should ru... 阅读全文

posted @ 2014-12-10 15:33 远近闻名的学渣 阅读(114) 评论(0) 推荐(0)

leetcode : Insert Interval
摘要:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially... 阅读全文

posted @ 2014-12-10 15:24 远近闻名的学渣 阅读(119) 评论(0) 推荐(0)

leetcode : Jump Game I&II
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximu... 阅读全文

posted @ 2014-12-09 23:06 远近闻名的学渣 阅读(147) 评论(0) 推荐(0)

leetcode : Text Justification
摘要:Given an array of words and a lengthL, format the text such that each line has exactlyLcharacters and is fully (left and right) justified.You should p... 阅读全文

posted @ 2014-12-09 22:53 远近闻名的学渣 阅读(167) 评论(0) 推荐(0)

leetcode : Search in Rotated Sorted Array I&&II
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value t... 阅读全文

posted @ 2014-12-08 22:41 远近闻名的学渣 阅读(144) 评论(0) 推荐(0)

导航