摘要: 1、经典八皇后问题 要在8*8的国际象棋棋盘中放8个皇后,使任意两个皇后都不能互相吃掉。规则是皇后能吃掉同一行、同一列、同一对角线的棋子。问有多少种摆法。 package dfs; public class EightQueen { /** * @param args */ static int c 阅读全文
posted @ 2020-05-05 10:12 柠檬不酸i 阅读(324) 评论(0) 推荐(0) 编辑
摘要: 例1: import java.util.Scanner; import java.util.Arrays; class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n = 阅读全文
posted @ 2020-04-29 11:34 柠檬不酸i 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 例1: import java.util.Scanner; class jianbaozang{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int c 阅读全文
posted @ 2020-04-28 10:31 柠檬不酸i 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 例1: def jianshuiguo(n,ans): dp=[[0 for i in range(n+1)]for j in range(n+1)] dp[1][0]=ans[1][0] # print(dp) sum=0 for i in range(2,n+1): for j in range 阅读全文
posted @ 2020-04-28 08:32 柠檬不酸i 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 例1: def ditui(n,m,cx,cy): x=[1,1,2,2,-1,-1,-2,-2] y=[2,-2,1,-1,2,-2,1,-1] d=[[0 for i in range(n+1)]for j in range(m+1)] f=[[0 for i in range(n+1)]for 阅读全文
posted @ 2020-04-25 16:29 柠檬不酸i 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 1、斐波那契数列 题目描述 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。 n<=39 class Solution: def Fibonacci(self, n): # write code here if n==0: return 0 if 阅读全文
posted @ 2020-04-24 10:57 柠檬不酸i 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 1、用两个栈实现队列 题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 class Solution: def __init__(self): self.stack1=[] self.stack2=[] def push(self, node): # w 阅读全文
posted @ 2020-04-22 10:24 柠檬不酸i 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 1、重建二叉树 题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。 例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。 # def __init__(se 阅读全文
posted @ 2020-04-22 09:54 柠檬不酸i 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 1、从尾到头打印链表 题目描述 输入一个链表,按链表从尾到头的顺序返回一个ArrayList。 # -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None cl 阅读全文
posted @ 2020-04-19 22:08 柠檬不酸i 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 1、替换空格 题目描述 请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。 class Solution: # s 源字符串 def replaceSpace(self, s): # writ 阅读全文
posted @ 2020-04-19 18:23 柠檬不酸i 阅读(89) 评论(0) 推荐(0) 编辑