10 2014 档案
摘要:使用栈结构解决。#include #include using namespace std;class Solution {public: int trap(int A[], int n) { if (n water_stack; int begin=0; ...
阅读全文
摘要:递归实现(python):# Definition for a binary tree nodeclass TreeNode: def __init__(self, x): self.val = x self.left = None self...
阅读全文
摘要:典型的用栈(stack)结构解决问题的例子class Solution: def isPair(self,s1,s2): if (s1=='(' and s2==')')or (s2=='(' and s1==')'): return True ...
阅读全文
摘要:我的思路:先读取每一个单词,存放到容器中;读取完毕后,将容器中的单词倒序写入输出中。#include#include#includeusing namespace std;void f(string &s){ vector vs; string temp=""; int i=0;...
阅读全文
摘要:贪心:尽量将gas[i]-cost[i]>0的放在前面,gas[i]-cost[i]=sum(cost[i]),不满足这个条件就不能全程走一遍;起点 i 满足的 必要 条件 是:额外剩下的gas(additional_gas)要大于等于0,即 gas[i]-cost[i]>=0;另外需满足: 找出某...
阅读全文
摘要:快速比较两个字符串是否“相等”两个字符串相等:字符串中的每个字符出现的次数都相等。“abbcc”与“cbabc”相等,因为两个字符串中‘a’都出现了1次,‘b’出现2次,‘c’出现2次。其中一种方法是使用散列表,散列表的经典应用是字典,以单词为关键字,其解释为值; 对于本文的问题, 将字符作为关键字...
阅读全文
摘要:# Definition for a binary tree nodeclass TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Noneclas...
阅读全文
摘要:class Solution: # @param a, a string # @param b, a string # @return a string def addBinary(self, a, b): #长度不等,补齐 len_a=len(a...
阅读全文
摘要:给出待选数字集合和目标值,要求得到所有的和为目标值的子集;例如 待选数字集合{ 2,3,6,7 },目标值7 ,=> { {2,2,3},{7} }可用递归,则递推式为:f([2,3,6,7],7)={{2+f([2,3,6,7],5)},{3+f([3,6,7],4)},{6+f([6,7],1)...
阅读全文
摘要:For example, given array S = {-1 2 1 -4}, and target = 1.The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).想来想去想不到什么好的解决方法,只好用最原始的方法,把所有可能的...
阅读全文
摘要:动态规划class Solution: # @param triangle, a list of lists of integers # @return an integer def minimumTotal(self, triangle): depth=len(tr...
阅读全文
摘要:# Definition for singly-linked list.class ListNode: def __init__(self, x): self.val = x self.next = Noneclass Solution: # @para...
阅读全文
摘要:class Solution: # @return a string def longestCommonPrefix(self, strs): num_items=len(strs) if num_itemslen(i): pre...
阅读全文
摘要:LeetCode 1 class Solution: 2 # @return a string 3 def countAndSay(self, n): 4 if n==1: 5 return "1" 6 else: 7 ...
阅读全文

浙公网安备 33010602011771号