
编程学习
ok0011
这个作者很懒,什么都没留下…
展开
-
整数数组能组成的最大数字
public class Temp { public static String largestNumber(int[] nums) { String[] numStrArray = new String[nums.length]; for (int i = 0; i < nums.length; i++) { numStr...原创 2020-04-15 17:30:41 · 1261 阅读 · 0 评论 -
字母序列和数字转换
public class Temp { //数字转字母序列 -> 10进制转26进制 public static String numToLetters(int num) { if (num <= 0) { return ""; } String result = ""; whi...原创 2020-04-13 23:16:40 · 678 阅读 · 0 评论 -
八皇后问题
import java.util.ArrayList;import java.util.List;public class Temp { public static int[][] chessboard = new int[8][8]; public static List<String> solutionStrs = new ArrayList<>...原创 2020-04-13 22:14:09 · 291 阅读 · 0 评论 -
数组中寻找峰值
public class Solution { //只存在一个峰值 public static Integer findMaxNum(int[] nums) { if (nums == null || nums.length == 0) { return null; } int len = nums.length...原创 2020-04-13 21:42:06 · 763 阅读 · 0 评论 -
数组右移后二分查找
import java.util.Arrays;public class Temp { //右移数组m位 public static void shiftArray1(int[] data, int m) { int len = data.length; while (m-- > 0) { int temp = d...原创 2020-04-09 22:25:49 · 324 阅读 · 0 评论 -
矩阵从左上角到右下角的最小路径值
public class Temp { public static int minPathNum(int[][] data, int startI, int startJ, int endI, int endJ) { int sum = Integer.MAX_VALUE; int i = startI; int j = startJ;...原创 2020-04-08 12:34:18 · 1249 阅读 · 0 评论 -
约瑟夫环报数出列问题
public class Temp { public static void printYuesefuNum(int total, int k) { int[] data = new int[total]; for (int i = 0; i < total; i++) { data[i] = i + 1; }...原创 2020-04-06 20:14:58 · 444 阅读 · 0 评论 -
求两个字符串的最大公共子串
public class Temp { public static String lcs(String a, String b) { if (a == null || b == null || a.length() == 0 || b.length() == 0) { return ""; } int aLen =...原创 2020-03-22 16:54:09 · 260 阅读 · 0 评论 -
java nio demo
Serverimport java.io.IOException;import java.net.InetSocketAddress;import java.nio.ByteBuffer;import java.nio.channels.SelectionKey;import java.nio.channels.Selector;import java.nio.channels.Serve原创 2016-07-21 15:56:41 · 273 阅读 · 0 评论 -
最长递增子序列 nlogn
import java.util.Arrays;public class Solution { public int LIS(int[] array) { int[] temp = new int[array.length]; temp[0] = array[0]; int maxLen = 1; int i = 1;原创 2016-06-09 22:01:50 · 498 阅读 · 0 评论 -
二分查找排序数组中指定数所在区间
import java.util.Arrays;public class Solution { //??1 public int[] searchRange(int[] nums, int target) { if (nums == null || nums.length == 0) return new int[]{-1, -1};原创 2016-08-02 00:14:21 · 721 阅读 · 0 评论 -
内存分配指令执行器
import java.util.ArrayList;import java.util.List;import java.util.Scanner;class Mem { int handle; int start; int count; public Mem(int handle, int start, int count) { this.hand原创 2016-09-11 11:22:21 · 337 阅读 · 0 评论 -
小明看旗
import java.util.Scanner;public class Main{ public static boolean isForward(String line, String target1, String target2){ int pos = -1; pos = line.indexOf(target1); if(pos =原创 2016-09-11 11:37:19 · 673 阅读 · 0 评论 -
数组中相加之和等于特定值的元素
import java.util.ArrayList;import java.util.Arrays;import java.util.List;public class Solution { public List<List<Integer>> combinationSum(int[] candidates, int target) { List<List<Intege原创 2016-08-02 15:41:37 · 3541 阅读 · 0 评论 -
Next Permutation
import java.util.Arrays;public class Solution { public void nextPermutation(int[] nums) { if (nums == null || nums.length <= 1) return; int i = nums.length - 1;原创 2016-08-01 22:12:11 · 251 阅读 · 0 评论 -
找出数组中相加之和等于特定值的四个数
import java.util.ArrayList;import java.util.Arrays;import java.util.List;public class Solution { //解法1 public List<List<Integer>> fourSum1(int[] nums, int target) { if (nums == null |原创 2016-08-01 16:02:21 · 1212 阅读 · 0 评论 -
旋转矩阵
import java.util.Arrays;public class Solution { //顺时针旋转90度 public void rotate(int[][] matrix) { for (int i = 0, j = matrix.length - 1; i < j; i++, j--) { int[] temp = matrix原创 2016-09-17 13:16:31 · 360 阅读 · 0 评论 -
全排列-字典序
import java.util.Scanner;public class Solution { static int count = 2; public static void swap(char[] arr, int i, int j) { char tmp = arr[i]; arr[i] = arr[j]; arr[j] = tm原创 2016-09-28 21:52:58 · 278 阅读 · 0 评论 -
求数组中不重复的两个数
import java.util.Arrays;public class Solution { public int[] singleNumber(int[] nums) { int[] result = new int[2]; int res = 0; for(int d : nums){ res ^= d;原创 2016-05-25 23:01:11 · 954 阅读 · 0 评论 -
java判断字符是否是汉字
public class Demo { public static boolean isChinese(char c) { Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS原创 2017-08-09 15:09:42 · 450 阅读 · 0 评论 -
汉字数字转阿拉伯数字
import org.apache.commons.lang3.StringUtils;import java.util.ArrayDeque;import java.util.ArrayList;import java.util.Deque;import java.util.HashMap;import java.util.List;import java.util.Map;public原创 2017-07-22 09:06:33 · 423 阅读 · 0 评论 -
01背包
import java.util.Scanner;public class Main { public static void main(String argv[]) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int n = in.nextInt();原创 2016-09-28 22:14:24 · 262 阅读 · 0 评论 -
求一个数组中连续子数组的最大乘积
public class Solution { public int maxProduct(int[] nums) { if (nums == null || nums.length == 0) { return 0; } if (nums.length == 1) { return nums[0]原创 2016-10-08 17:34:15 · 1041 阅读 · 0 评论 -
求数组排序后相邻两个数的最大差值
import java.util.Arrays;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) {原创 2016-10-16 13:07:48 · 1325 阅读 · 1 评论 -
全组合
import java.util.ArrayList;import java.util.List;public class Solution { public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> result = new ArrayList<>(); result.add(原创 2016-09-29 00:16:03 · 306 阅读 · 0 评论 -
组合 N选K
import java.util.ArrayList;import java.util.Arrays;import java.util.List;public class Solution { public void add(int[] array, int[] nums, List<List<Integer>> result) { List<Integer> list =原创 2016-09-28 23:51:45 · 412 阅读 · 0 评论 -
全排列 去重 非字典序
import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;public class Solution { public List<List<Integer>> permute(int[] nums) { List<List<Integer>原创 2016-09-28 22:59:09 · 330 阅读 · 0 评论 -
大整数相乘
import java.math.BigInteger;public class Solution { //解法1 public String multiply(String num1, String num2) { if (num1 == null || num1.length() == 0 || (num1.length() == 1 && num1.trim()原创 2016-08-02 17:51:18 · 246 阅读 · 0 评论 -
合并两个有序数组
import java.util.Arrays;public class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int p = m + n; int i = m - 1; int j = n - 1; while (--p >=原创 2016-06-04 13:16:07 · 244 阅读 · 0 评论 -
之字形字符串转换
import java.util.ArrayList;import java.util.List;public class Solution { public String convert(String s, int numRows) { if(s == null || s.trim().isEmpty() || s.length() <= numRows || numRo原创 2016-06-07 22:18:49 · 644 阅读 · 0 评论 -
整数数组按频率和大小排序
import java.util.Arrays;import java.util.Comparator;import java.util.HashMap;import java.util.Map;public class tt { public static void main(String[] args){ //数字排序,按频率由低到高,相同频率按数字大小排序原创 2016-05-20 22:09:05 · 1668 阅读 · 0 评论 -
最长递增子序列
package algorithm;public class LongestIncreasingSubsequence { void getLIS(int[] array){ /** *max:最长递增序列元素个数 *maxIndex:最长递增序列中最后一个元素的下标 *preIndex:保存最长子序列各个元素,原创 2016-04-06 23:17:56 · 244 阅读 · 0 评论 -
01背包问题
import java.util.ArrayList;import java.util.Arrays;import java.util.List;public class OneZeroBag { public static class Item{ char name; int weight; int value; publi原创 2016-05-31 21:59:00 · 263 阅读 · 0 评论 -
单链表排序
import java.util.ArrayList;import java.util.List;class ListNode { int val; ListNode next; ListNode(int x) { val = x; }}public class Solution { //快速排序 public ListNode sortList(List原创 2016-05-30 20:16:37 · 257 阅读 · 0 评论 -
数组去重
import java.util.Arrays;import java.util.Set;import java.util.TreeSet;public class Solution { public int removeDuplicates1(int[] nums) { if(nums == null || nums.length == 0){原创 2016-05-25 00:13:57 · 221 阅读 · 0 评论 -
最大间距问题
public class MaxGap { static class Bucket{ int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; } public static int getMaxGap(int[] array){ int n = array.length,原创 2016-04-28 23:58:46 · 595 阅读 · 0 评论 -
整数转二进制
package algorithm;import java.util.ArrayList;import java.util.List;public class Solution { List<Integer> getBinary(int num){ List<Integer> binary = new ArrayList<>(); while(num > 0)原创 2016-04-06 22:05:00 · 365 阅读 · 0 评论 -
大整数的阶乘
#include <iostream>using namespace std;int main(){ int n; while(cin >> n) { if(n == 0 || n == 1) cout << 1 << endl; else { int a[10000] =原创 2015-07-07 15:52:19 · 402 阅读 · 0 评论 -
求1到n中1的个数
public class Solution { public int countDigitOne(int n) { long sum = 0; long factor = 1; while(n/factor != 0){ long lower = n%factor; long curr = (n/原创 2016-05-22 16:18:55 · 410 阅读 · 0 评论 -
判断单链表回文
class ListNode { int val; ListNode next; ListNode(int x) { val = x; }}public class Solution { public boolean isPalindrome(ListNode head) { if(head == null原创 2016-05-22 18:12:17 · 366 阅读 · 0 评论