【博学谷学习记录】超强总结,用心分享|【面试专题】算法面试题精选(一)

这篇博客汇总了面试中常见的算法题目,包括Two Sum II、Sum of Square Numbers、Reverse String、Reverse Vowels of a String以及Kth Largest Element in an Array。对于寻找第K大元素的问题,介绍了使用排序、堆和快速排序的方法,其中快速排序在时间复杂度和空间复杂度上表现出色。
摘要由CSDN通过智能技术生成

目录

1.Two Sum II - Input array is sorted(167)

2. Sum of Square Numbers(633)

3. Reverse String(344)

4. Reverse Vowels of a String(345)

5.Kth Largest Element in an Array(215)


 

1.Two Sum II - Input array is sorted(167)

package com.problem167;

class Solution {
    public int[] twoSum(int[] numbers, int target) {
        int i = 0, j = numbers.length - 1;
        int[] result = new int[2];
        int temp;
        while (i < j){
            temp = numbers[i] + numbers[j];
            if (temp == target){
                result[0] = i + 1;
                result[1] = j + 1;
                break;
            }else if (temp < target){
                i++;
            }else{
                j--;
            }
        }
        return result;
    }
}

2. Sum of Square Numbers(633)

pack
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值