码迷,mamicode.com
首页 >  
搜索关键字:reverse intger    ( 5102个结果
【剑指offer】数组中的逆序对
# @left part: [start, mid] # @right part: (mid, end] def merge(data, start, mid, end): if mid < start or end < mid: return 0 reverse = 0 ''' @ for start, it play as the start index of left par...
分类:其他好文   时间:2014-07-08 15:04:06    阅读次数:204
用递归翻转一个栈 Reverse a stack using recursion
明确递归语句之前的语句都是顺序执行,而递归语句之后的语句都是逆序执行package recursion; import java.util.Stack; public class Reverse_a_stack_using_recursion { /* Input stack: 3 2 1 Output stack: 1 2 3 */ public s...
分类:其他好文   时间:2014-07-08 13:39:49    阅读次数:143
【leetcode】:Evaluate Reverse Polish Notation (python)
逆波兰式的求解,建立一个类栈容器,遍历给定的逆波兰表达式,遇到数字就push, 遇到操作符就进行出栈,连续出两次,因为给定的四则运算符都是双目的,这里注意下这两个操作数的先后顺序,因为对于加法和乘法没关系,但是对于减法和除法是有先后关系的。然后进行相应的运算,将结果push进栈中。 这里附带说明下python中进行除法运算与c,java系列中的除法的不同,就是向下取整的问题。这种不同表现在两个操...
分类:编程语言   时间:2014-07-06 12:22:02    阅读次数:235
【剑指offer】Q5:从尾到头打印链表
可以练习下链表的逆置。 def PrintListReversingly(head): if head == None: return if head: PrintListReversingly(head.next) print head.val def reverse(head): if head == None or head.next == None: return...
分类:其他好文   时间:2014-07-06 09:29:57    阅读次数:214
【leetcode】Reverse Words in a String (python)
陆陆续续几个月下来,终于把题刷完了,过程中遇到的python的题解很少,这里重新用python实现下,所以题解可能都是总结性的,或者是新的心得,不会仅针对题目本身说的太详细。 def reverseWords(self, s): s = ' '.join(s.split()[::-1]) return s [ : :  -1 ] 是将元素进行翻转...
分类:编程语言   时间:2014-07-06 00:37:50    阅读次数:299
Java Evaluate Reverse Polish Notation(逆波兰表达式)
表达式:   ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9   ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6 题目大意:给定一个逆波兰表达式,求该表达式的值 思路:由于逆波兰表达式本身不需要括号来限制哪个运算该先进行,因此可以直接利用栈来模拟计算:遇到操作数直接压栈,碰到操作符直接取栈顶的2...
分类:编程语言   时间:2014-07-06 00:07:22    阅读次数:296
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...
分类:其他好文   时间:2014-07-03 23:51:47    阅读次数:408
LeetCode OJ——练习笔记(1)Evaluate Reverse Polish Notation
院招终于开始了,然后期待与兴奋过后却是面临着笔试一次又一次的失败,然后开始留意到LeetCode。也想自己去体验一下诸多大牛通向无限coding路上都攻克过的一关。话不多说,贴出原题:Evaluate the value of an arithmetic expression inReverse P...
分类:其他好文   时间:2014-07-03 22:01:50    阅读次数:202
LeetCode——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".Clarification:What constitutes...
分类:其他好文   时间:2014-07-03 20:45:35    阅读次数:201
[LeetCode]Reverse Integer
[LeetCode]Reverse Integer...
分类:其他好文   时间:2014-07-03 16:36:33    阅读次数:121
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!