本题是力扣网第50题. 实现 pow(x, n) ,即计算 x 的 n 次幂函数. 采用递归和非递归思路python实现. class Solution: #递归思路 def myPow_recursion(self,x,n): if n == 0: #递归终止条件,n==0返回1 return 1 if n < 0: #n小于0,就返回其倒数,-n和其递归结构一致 return 1 / self.myPow_recursion(x,-n) if n & 1: #判断是奇数,则结果为x*(x…
Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,2,3] Follow up: Recursive solution is trivial, could you do it iteratively? Solution: 很简单,使用栈,先存入右节点,再存入左节点,这样就是先弹出左节点了 class S…
Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.With each iteration one element (red) is removed from the input data and inserted in…