
算法
NameNoteFound
这个作者很懒,什么都没留下…
展开
-
leetcode #4: Median of Two Sorted Arrays
题目链接: Median of Two Sorted Arrays这道题坑还是有点多的,刚看到的时候第一反应是:这不就是归并排序....还是图样啊。所以先这样提交了:class Solution(object): def findMedianSortedArrays(self, nums1, nums2): """ :type nums1:原创 2016-07-31 00:33:51 · 338 阅读 · 0 评论 -
Leetcode #39. Combination Sum
Leetcode #39. Combination Sum题目https://leetcode.com/problems/combination-sum/description/代码class Solution {public: void foo(vector<int>& candidates, int target, int cidx, vect...原创 2018-04-12 20:08:17 · 212 阅读 · 0 评论 -
Leetcode #121. Best Time to Buy and Sell Stock
Leetcode #121. Best Time to Buy and Sell Stock题目https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/代码class Solution {public: int maxProfit(vector<int>& pr...原创 2018-04-11 23:39:51 · 190 阅读 · 0 评论 -
Leetcode #231. Power of Two
Leetcode #231. Power of Two题目https://leetcode.com/problems/power-of-two/description/代码我的:class Solution {public: bool isPowerOfTwo(int n) { if (n <= 0) return false; ...原创 2018-04-11 23:31:48 · 164 阅读 · 0 评论 -
Leetcode #780. Reaching Points
Leetcode #780. Reaching Points题目https://leetcode.com/problems/reaching-points/description/代码一开始的思路是逆向推,目的坐标(tx, ty)肯定是由(tx-ty, ty)或(tx, ty-tx),但是坐标限定不为负数,因此比较tx、ty的大小可以唯一确定上一步的步骤于是有:cl...原创 2018-04-10 23:23:55 · 246 阅读 · 0 评论 -
Leetcode #746. Min Cost Climbing Stairs
Leetcode #746. Min Cost Climbing Stairs题目https://leetcode.com/problems/min-cost-climbing-stairs/description/代码Simple Question. 没啥好说的,数组那里优化下,用两个变量就可以。class Solution {public: int minCo...原创 2018-04-10 22:40:40 · 183 阅读 · 0 评论 -
Leetcode #395. Longest Substring with At Least K Repeating Characters
Leetcode #395. Longest Substring with At Least K Repeating Characters题目链接https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/description/代码思路:首先检查当前字符串是否满足...原创 2018-04-10 22:23:07 · 159 阅读 · 0 评论 -
Leetcode #7. Reverse Integer
class Solution: def reverse(self, x): """ :type x: int :rtype: int """ ret = 0 nega = 0 if x > 0 else 1 if nega: x = -x原创 2017-12-26 01:18:55 · 237 阅读 · 0 评论 -
#6. ZigZag Conversion
1. 题目ZigZag字符串的描述见题目链接。给定行号,对于一个ZigZag字符串,需要按行号顺序输出每行的内容。2. 代码# 比较简单,将ZigZag字符串按顺序遍历,每个字符放入对应行中class Solution(object): def convert(self, s, numRows): """ :type s: str :type原创 2017-02-10 03:35:06 · 272 阅读 · 0 评论 -
Leetcode #516. Longest Palindromic Subsequence
Leetcode #516. Longest Palindromic Subsequence题目https://leetcode.com/problems/longest-palindromic-subsequence/description/代码比较典型的动态规划问题。递归写了一遍TLE了,循环方法没有问题。class Solution {public: ...原创 2018-05-06 17:09:03 · 195 阅读 · 0 评论