java算法
再别康桥_Victor
这个作者很懒,什么都没留下…
展开
-
算法:子数组的最大累加和问题
public int maxSum(int[]arr){ if(arr == null || arr.length==0){ return 0; } int max = Integer.MIN_VALUE; int cur=0; for (int i=0;i != arr.length;i++) { cur+=arr[i]; max = Math.max(.原创 2021-07-17 22:26:03 · 64 阅读 · 0 评论 -
算法:删除有序链表中重复出现的元素
//Javapublic ListNode deleteDuplicates(ListNode head) { ListNode dummy = new ListNode(-1); dummy.next = head; ListNode prev = dummy; ListNode curr = head; while (curr != null && curr.next != null) { if (curr.val == cu.原创 2021-06-27 19:20:37 · 80 阅读 · 0 评论 -
算法:最长无重复子数组
public int maxLength(int[] arr){ int n = arr.length; Set<String> set = new HashSet<String>(); int i=0, j=0, ans=0; while(i<n && j<n){ if(!set.contains(arr[j])){ set.add(arr[j]); j++; .原创 2021-06-27 19:08:56 · 141 阅读 · 0 评论 -
算法: 给出一组非负整数,重新排列他们的顺序把他们组成一个最大的整数。
public class App{ public static void main(String[] args ) { Integer[] input = {3, 30, 34, 5, 9}; int inputLength = input.length; int tmp; while (inputLength!=0){ for (int j=1;j if (App....原创 2021-06-24 22:01:31 · 1049 阅读 · 0 评论 -
算法: 滑动窗口的最大值
int getMax(const int A[],int size){ int mx=A[0]; for(int i=1;i if(A[i]>mx) mx=A[i]; } return mx;}vector maxInWindows(const int A[],int n,int size){ vector result; for(int i=0;i int num=getMax(A+i,siz...原创 2021-06-24 21:48:38 · 56 阅读 · 0 评论 -
算法:无重复字符的最长子串(数组)
/** * 无重复字符的最长子串 * @param s * @return */ public int lengthOfLongestSubstring(String s) { int [] freq= new int[256]; for(int i =0;i<freq.length;i++){ freq[i] = 0; } //滑动窗口[left...right].原创 2021-06-17 18:33:05 · 68 阅读 · 0 评论 -
算法:反转一个单链表
struct ListNode *reverseList(struct ListNode* head) { struct ListNode *newHead = NULL; struct ListNode *node; while (head != NULL) { //1. 对之前的链表做头删 node = head; head = head->next; //2. 对新链表做头插 node->next = newHead; newHead = node;原创 2021-06-17 18:29:37 · 108 阅读 · 1 评论 -
算法:java多线程模拟停车系统
import java.util.Random;import java.util.concurrent.ArrayBlockingQueue;import java.util.concurrent.BlockingQueue;import java.util.concurrent.Semaphore;import java.util.concurrent.SynchronousQueue;...原创 2020-04-04 20:13:10 · 267 阅读 · 0 评论 -
算法:把数组中数字连起来组成一个最小的数字
import java.util.Arrays;import java.util.Scanner;public class test2 {public static void main(String[] args) {Scanner scan = new Scanner(System.in);String result = “”;while(scan.hasNext()){int n...原创 2020-02-06 18:08:17 · 422 阅读 · 0 评论