在面试中,为了缓解面试的尴尬,有些面试会然你写一写简单算法题来缓解气氛比如冒泡啊简单的算法题,今天给大家带了一道我遇到的一道算法题分享给他就,思路都写在对应代码的注释上,不懂可以看一下,有什么写的不对的大家可以指出来上代码
package com.interview;
import com.sun.javafx.image.BytePixelSetter;
public class Test2 {
public static void main(String[] args) {
String str1 = "568658123123312123123123123123131233132123123123131231233123131231231231231";
String str2 = "132121231231231312312312312312312312312312312312313123123101";
//reverse()方法是将字符串反转。
//StringBuffer类是一个可变字符串类,它可以用来存储字符串。
StringBuffer s1 = new StringBuffer(str1).reverse();
StringBuffer s2 = new StringBuffer(str2).reverse();
StringBuffer res = new StringBuffer();
int len1 = s1.length();
int len2 = s2.length();
int len;
//如果两个字符串长度不一样,则取长度较大的那个字符串的长度。
if (len1 < len2) {
//意思是:如果len1<len2,则len=len2,否则le