- 博客(26)
- 资源 (3)
- 收藏
- 关注
原创 力扣LCP17 速算机器人
class Solution { public int calculate(String s) { int x = 1,y = 0; char[] str = s.toCharArray(); for(char c: str){ if(c=='A') x = 2 * x + y; else if(c=='B') y = 2 * y + x;
2020-10-27 09:55:26 107
原创 力扣1365有多少小于当前数字的数(迭代双桶)
class Solution { public int maximumProduct(int[] nums) { Arrays.sort(nums); int len = nums.length; return Math.max(Math.max((nums[0]*nums[1]*nums[len-1]),nums[len-3]*nums[len-2]*nums[len-1]),nums[0]*nums[1]*nums[2]); }}
2020-10-26 10:14:23 63
原创 二分法查找 (Java,c++)
class Solution { public int search(int[] nums, int target) { int pivot, left = 0, right = nums.length - 1; while (left <= right) { pivot = left + (right - left) / 2; if (nums[pivot] == target) return pivot; if (target < nu
2020-10-22 11:13:58 56
原创 java语言程序设计(进阶版)21.6 21.10 HashMap
package com.wenchi;import java.util.HashMap;import java.util.Iterator;import java.util.Scanner;import java.util.TreeMap;public class Demo01 { public static void main(String[] args) { HashMap<Integer, Integer> hashMap = new HashMap&
2020-10-22 10:40:21 287 4
原创 java语言程序设计(进阶版)17.1 17.16 17.3 IO流
package com.company;import javafx.scene.effect.ImageInput;import java.io.*;public class Demo02 { public static void main(String[] args) throws Exception{ File file = new File("d:\\Exercise17_01(2).txt");// BufferedWriter out = new
2020-10-21 13:00:35 165
原创 九九乘法表(C语言)
#include<stdio.h>main(){ for(int i=1;i<=9;i++){ for(int j=1;j<=i;j++){ printf("%d*%d=%d ",i,j,i*j); } putchar('\n'); }}
2020-10-12 10:34:43 133
原创 力扣104(二叉树的最大深度)
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public int maxDepth(TreeNode root) { if(root==null)
2020-10-12 10:17:47 115
原创 力扣867(转置矩阵)
class Solution { public int[][] transpose(int[][] A) { int [][]a= new int [A[0].length][A.length]; for(int i=0;i<A.length;i++) for(int j=0;j<A[0].length;j++) a[j][i]=A[i][j]; return a; }}
2020-10-12 09:58:24 122
原创 力扣79(单词搜索)dfs回溯算法 (3)java
class Solution { public boolean exist(char[][] board, String word) { for(int i = 0;i < board.length;i++) for(int j = 0;j < board[0].length;j++) if(dfs(board,word,i,j,0)) return true;
2020-10-11 17:26:08 87
原创 力扣79(单词搜索)dfs回溯算法 (2)java
class Solution{private char[] words;private String word;private int n,m;private char[][] board;private int[][] direction ={{0,-1},{1,0},{0,1},{-1,0}};public boolean exist(char[][] board, String word) { this.word = word; words = word.toCharA
2020-10-11 16:56:31 96
原创 力扣79(单词搜索)dfs回溯算法 java
// "static void main" must be defined in a public class.class Solution { private char [][] board; private String word; private int [][] direction; private int n,m; private boolean [][] marked; public boolean exist(char[][] bo
2020-10-11 16:10:12 152
原创 插入排序 (C语言)
#include<stdio.h>void insertionSort(int a[],int len){ for(int i=1,j;i<len;i++){ int key = a[i]; for(j=i-1;j>=0&&key<a[j];j--){ a[j+1] = a[j]; } a[j+1] = key;//记得加1,因为j相比边界多减了一个 }}//分开的写法,可能更便于理解//void insert(int a[]
2020-10-10 18:37:48 135
原创 选择排序 (C语言)
#include<stdio.h>void Selection (int a[],int len){ for(int i=0;i<len-1;i++){ //i代表子序列的第一位,一开始子序列等于整个序列,i<len-1并不是防止越界,而是没有必要 int min = a[i];//这一步很巧妙,与最后的赋值互相呼应 int minIndex = i; for(int j=i;j<len;j++){//每次选择一个最小的放在子序列第一位 if(a[j]
2020-10-10 17:31:46 102
原创 冒泡排序 (C语言)
#include<stdio.h>int *bubble(int a[],int len){// int len = sizeof(a)/sizeof(int); //这样写是错误的,因为a传进来的是个指针,sizeof(a)是8 for(int i=0;i<len-1;i++) for(int j=0;j<len-1;j++) if(a[j]>a[j+1]){ int t = a[j]; a[j] = a[j+1]; a[j+1] =
2020-10-10 16:47:41 1674 5
原创 java分解质因数,求质因数个数(continue在for循环下需要注意的事情)
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int res = 0; int i; for (i = 2;i <= n;i++) {//i从2开始,因为n动
2020-10-10 12:08:52 727 1
原创 杭电hdu2072(单词数)
import java.util.ArrayList;import java.util.List;import java.util.Scanner;public class Main { public static void main(String []args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()) { String a=sc.nextLine(
2020-10-10 11:22:09 177
原创 杭电2041(斐波那契/动态规划)
#include<stdio.h>int main(){ int N; scanf("%d",&N); int a[45]; a[2]=1; a[3]=2; for(int i=4;i<=40;i++) a[i]=a[i-1]+a[i-2]; for(int i=0;i<N;i++){ int n; scanf("%d",&n); printf(
2020-10-09 13:39:32 113 1
原创 java语言程序设计(进阶版)19.4 19.5
public class Demo06 { public static <E extends Comparable<E>> E max(E[]list){ E max; if(list==null) return null; else { max = list[0]; } for(E t:list){ if(t.compar.
2020-10-09 13:31:11 141
原创 兔子问题(斐波那契数列)的迭代实现与递归实现
某个月兔子的数量=上个月兔子数+这个月出生的兔子数这个月出生的兔子数=上上个月的兔子数(根据题意可知此时且这个月的兔子全是上上个个月的兔子生的,因为上上个月的兔子是刚好到这个月所有兔子都成熟的,所以可以理解为这个月的新生兔子是上上个月的兔子数量)。写成递推公式就是:f(n)=f(n-1)+f(n-2).其实就是一个斐波那契数列代码的话1:可以一开始定义一个数组,把每个月的兔子数都存进去,最后然后通过索引输出n个值。2:也可以每次输入一个月份后,用两个变量(三个也行)从头迭代到该月份,然后输出
2020-10-09 12:57:06 840
原创 java语言程序设计(进阶篇)19.1泛型的应用
package com.company;import java.util.Arrays;public class GenericStack<E> { Object [] a = new Object[10];// int max = a.length; int size = 0; // E[] array = new [10]; 不可这么写 public int getSize() { return size; }
2020-10-09 12:47:07 176
原创 力扣20(括号匹配)(两种方法的最简单版本)
class Solution { public boolean isValid(String s) { Deque<Character> st = new ArrayDeque<>(); char[] chrs = s.toCharArray(); int len = chrs.length,t = 0; while (t < len)//count==len时,下面的索引值==数组最大下标
2020-10-05 16:51:37 263 2
原创 括号匹配(java最简单版本)
class Solution { public boolean isValid(String s) { Deque<Character> st = new ArrayDeque<>(); char[] chrs = s.toCharArray(); int len = chrs.length,t = 0; while (t < len)//count==len时,下面的索引值==数组最大下标
2020-10-05 16:49:17 178
原创 力扣27
class Solution { public int removeElement(int[] nums, int val) { int j=0; for(int i=0;i<nums.length;i++) if(nums[i]!=val) nums[j++]=nums[i]; return j; }}
2020-10-04 23:56:33 113
原创 求图内度为1的点的总数
#include<stdio.h>#include<string.h>#define MVNum 100 //????? typedef struct{ char vexs[MVNum]; //??? int arcs[MVNum][MVNum]; //???? int vexnum,arcnum; }AMGraph; void create(AMGraph &g,int n){
2020-10-03 13:02:07 73
原创 试管问题(求递推公式)MATRIX MULTIPLICATION CALCULATOR
Eli is a teenager who loves to study chemistry. She recently joined a chemistry research lab.Dr. Phil wants her to just play around with some chemicals and observe their reaction.Therefore, he gave her a one-row tray of test tubes with the different chem
2020-10-02 15:04:14 193
原创 C语言实现矩阵的相乘
#include<stdio.h>int main(){ int m,n,p,q,count=0; while(~scanf("%d %d %d %d",&m,&n,&p,&q)){ if(m==0&&n==0&&p==0&&q==0) break; count++; int a[m][n]={0},b[p][q]={0},c[m][q]={0}; for(i
2020-10-02 13:28:34 172 3
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人