一些算法题
来源:互联网 发布:卡密社区系统源码 编辑:程序博客网 时间:2024/06/08 02:25
下面都是我在网上搜集的算法题,我自己想了解法
1.一个严格递增的序列,从中间某个未知的地方切成两段,将前一段放到后面,求最大值?注意划开的位置你不知道!
我的解法
2.二维数组(N*N),沿对角线方向,从右上角打印到左下角如N=4:
{ 1 2 3 4 } { 5 6 7 8 } { 9 10 11 12 } {13 14 15 16 }
打印出来后
4 3 8 2 7 12 1 6 11 16 5 10 15 9 14 13
我的解答
package com.spring.test;/** * Created by brady on 15-1-14. */public class s { public static int[][] f(int n){ int[][] a = new int[2*n-1][n]; for(int i=n-1;i>=0;i--){ int aaa=i; for(int j=n-1;j>=0;j--){ a[aaa][i]=i*4+j+1; aaa++; } } return a; } public static void main(String[] args){ int n=4; int[][] a = f(n); for(int i=0;i<2*n-1;i++ ){ for(int j=0;j<4;j++) if(a[i][j]>0){ System.out.print(a[i][j] + " "); } System.out.println(); } }}
3.给你两个字符串str1,str2,找出str2在str1中的位置。
我的解答,没有用indexof
package com.spring.test;/** * Created by brady on 15-1-29. */public class Str { public static int f(String str,String s){ for(int i=0;i<str.length()-s.length();i++){ int k=0; if(str.charAt(i)==s.charAt(0)){ k=1; for (int j=1;j<s.length();j++){ if(str.charAt(i+j)==s.charAt(j)) k=1; else { k=0; break; } } } if(k==1) return i; } return -1; } public static void main(String[] args){ int a = f("sdgdddfgddddgggh","dddd"); System.out.println(a); }}
0 0
- 一些算法题
- 一些算法题
- 一些算法题
- 一些算法题
- 一些贪心算法题
- 一些算法题
- 一些算法题
- 一些算法题的实现
- java的一些算法题
- 一些智力题和算法题
- 遇到的一些算法题
- 一些数组的算法题
- java一些经典算法题
- 一些算法
- 一些算法
- 一些算法
- 一些算法
- 一些算法
- JS鼠标事件(监听鼠标点击/释放,鼠标悬停/离开等)
- Unity API 笔记
- 内部类,匿名内部类
- Jocky for Eclipse
- 啊哈C——学习3.2一起来找茬
- 一些算法题
- Go语言实现跳表(SkipList)
- C++强大背后
- 使用cgroup 限制进程的磁盘io
- 20150127
- 图解JAVA——接口与多态调用
- 三种常用算法概述——遍试、迭代、递归
- android:TableLayout表格布局详解
- 乔布斯经典名言