排序
【DP】使用最小花费爬楼梯
题目 给你一个整数数组 cost ,其中 cost[i] 是从楼梯第 i 个台阶向上爬需要支付的费用。一旦你支付此费用,即可选择向上爬一个或者两个台阶。 你可以选择从下标为 0 或下标为 1 的台阶开始爬楼...
【C】使用函数递归实现顺序数组二分查找
#include <stdio.h> int BinarySearch(int r[],int low,int high,int k){ int mid; if (low>high){ //若找不到,则返回-1,这也是递归终止条件 return -1; } else{ mid=(low+high)/2; //在顺...
【C】对一个分数约分
int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } void simplifyFraction(int *a, int *b) { int divisor = gcd(*...
【C】使用函数递归实现二分查找数组最大值
#include <stdio.h> //二分查找最大值 int Max(int r[],int low,int high){ int mid,maxL,maxR; if (low==high){ return r[low]; } else{ mid=(high+low)/2; maxL=Max(r,low,mid); maxR=Max(...
【递归】2的幂
递归法: class Solution: def isPowerOfTwo(self, n: int) -> bool: if n==1: return True if n<=0 or n%2!=0: return Fals...
【模拟】回文日期
题目 我的代码 import datetime ipt = input() begin = datetime.datetime(int(ipt[0:4]), int(ipt[4:6]), int(ipt[6:8])) flag1=0 flag2=0 while True: if flag1==1 and flag2==1: brea...