拼多多笔试

本文介绍了如何在Java中实现寻找数组中三个最大数的乘积,并提供了使用字符串表示大整数相乘的方法。通过具体实例展示了算法实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数组中最大的三个数乘积

public class Main {


    public static void main(String[] args) throws IOException {
    Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        int[] arrH = new int[n1];
        for (int j = 0; j < n1; j++) {
            arrH[j] = sc.nextInt();
        }


        int num = multiply(arrH);
        System.out.println(num);
   
    }
    public static int multiply(int [] a) {
    if(a.length<3){
    return 0;
    }
    if(a.length==3){
    return a[0]*a[1]*a[2];
    }
    int len = a.length;
    Arrays.sort(a);
    int b =a[0]*a[1]*a[len-1];
    int c =a[len-1]*a[len-1]*a[len-3];
    return b>c? b:c;
   
    }
       
}

用字符串表示大数字相乘

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * Created by Administrator on 2017-8-1.
 */
public class Main {


    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br= new BufferedReader(isr);
        String s = br.readLine();
        String[] inputs = s.split(" ");
        String num1 = inputs[0];
        String num2 = inputs[1];
        multiply(num1,num2);
    }
    public static String multiply(String num1, String num2) {
        if(num1.equals("0") || num2.equals("0")) return "0";
        int len1=num1.length();
        int len2=num2.length();
        int product,carry,i,j;
        int[] num= new int[len1+len2];
        for(i=len1-1;i>=0;i--){
            carry=0;
            for(j=len2-1;j>=0;j--){
                product=carry+ (int)(num1.charAt(i)-'0')*(int)(num2.charAt(j)-'0')+num[i+j+1];
                num[i+j+1]=product%10;
                carry=product/10;
            }
            num[i+j+1]=carry;
        }
        i=0;
        while(i<len1+len2 && num[i]==0){
            i++;
        }
        StringBuilder sb=new StringBuilder();
        while(i<len1+len2){
            sb.append(num[i]);
            i++;
        }


        System.out.println(sb);
        return sb.toString();
    }
}


import java.util.Scanner;
/**
 * Created by Administrator on 2017/8/1.
 */
public class  Main{
  public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n1 = sc.nextInt();
        int[] arrH = new int[n1];
        for (int j = 0; j < n1; j++) {
            arrH[j] = sc.nextInt();
        }
        int n2 = sc.nextInt();
        int[] arrW = new int[n2];
        for (int j = 0; j < n2; j++) {
            arrW[j] = sc.nextInt();
        }
        int num = countNum(arrH, arrW);
        System.out.println(num);
    }




    public static int countNum(int[] arrH, int[] arrW) {
        if (arrH == null || arrW == null || arrH.length == 0 || arrW.length == 0) {
            return -1;
        }
        sort(arrH);
        sort(arrW);
        int count = 0;
        for (int i = 0, j = 0; i < arrW.length && j < arrH.length; ) {
            if (arrW[i] >= arrH[j]) {
                j++;
                i++;
                count++;
            } else {
                j++;
            }
        }
        return count;
    }


    private static void sort(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = i + 1; j < a.length; j++) {
                if (a[j] > a[i]) {
                    int t = a[j];
                    a[j] = a[i];
                    a[i] = t;
                }
            }
        }
    }
}

### 关于拼多多笔试题中的服务端开发相关问题 对于参与拼多多的服务端开发岗位笔试,候选人通常会遇到一系列涉及计算机科学基础知识以及实际编程能力的问题。这些问题旨在评估候选人的算法设计、数据结构理解和服务架构思维。 #### 数据库管理与优化 数据库操作是服务端开发者日常工作中不可或缺的一部分。常见的面试题目可能围绕SQL查询效率提升展开,比如如何通过索引提高读取速度或者怎样重构复杂查询语句来减少资源消耗[^1]。 #### 分布式系统原理 分布式系统的理解和实现也是考察重点之一。这包括但不限于一致性哈希算法的应用场景分析、CAP理论的实际意义探讨等内容。了解这些概念有助于构建高可用性和可扩展性的网络应用程序[^2]。 #### 编程技能测试 除了理论知识外,编写高效且无误的代码同样重要。可能会被要求完成特定功能模块的设计与编码工作,例如实现一个简单的缓存机制或是处理并发请求的方法等。此外,掌握至少一种主流后端语言(如Python, Java 或者 Go)是非常必要的[^3]。 ```python def reverse_linked_list(head): prev = None current = head while current is not None: next_node = current.next # Store the next node temporarily. current.next = prev # Reverse the link direction. prev = current # Move 'prev' one step forward. current = next_node # Move to the next node in original list. return prev # New head of reversed linked list. ``` 上述代码展示了单向链表反转函数的一个简单例子,在某些情况下也可能作为基础考核点出现在类似的在线评测环境中。 #### 性能调优技巧 针对大型互联网公司的技术挑战,性能问题是不可避免的话题。能够识别并解决内存泄漏、CPU瓶颈等问题的能力显得尤为珍贵。熟悉Linux命令行工具集可以帮助快速定位故障所在,并采取有效措施加以改善.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值