为了账号安全,请及时绑定邮箱和手机立即绑定

java二道面试题

java二道面试题

DIEA 2019-04-11 18:15:24
2个问题1.有一个邮箱,有一千万条黑名单用户,怎么判断收件箱是不是黑名单用户。据说和字典什么的是属于同一个经典问题。。2.求一个字符串中最长的颠倒字符串。。比如 a123ghfuhg321asd131.(就是a123,321a.)
查看完整描述

6 回答

?
慕斯709654

TA贡献1840条经验 获得超5个赞

最长颠倒字符串应该是a123gh,hg321a

查看完整回答
反对 回复 2019-05-06
?
达令说

TA贡献1821条经验 获得超6个赞

第一个问题,用hash,把字符串转为数字去比对,数据的存储和查找都会比较快。
第二个问题,回文问题,上网找吧!

查看完整回答
反对 回复 2019-05-06
?
Cats萌萌

TA贡献1805条经验 获得超9个赞

public class Test {

/**
 * @param args
 */
public static void main(String[] args) {

    String a = "jha123ghfs343uhg321asd131";
    String str1 = null, str2 = null, tmpstr1 = null, tmpstr2 = null, maxstr1 = null, maxstr2 = null;

    for (int i = 0; i < a.length() - 2; i++) {

        for (int j = 2 + i; j < a.length() - 1; j++) {
            if (j > i) {
                str1 = a.substring(i, j);
                if (str1 != null && !str1.equals("") && str1.length() > 1) {
                    str2 = (new StringBuilder(str1)).reverse().toString();
                    if (a.indexOf(str2) == -1) {
                        if (tmpstr1 != null && (maxstr1 == null || tmpstr1.length() > maxstr1.length())) {
                            maxstr1 = tmpstr1;
                            maxstr2 = tmpstr2;
                        }
                        break;
                    } else {
                        tmpstr1 = str1;
                        tmpstr2 = str2;
                    }
                }
            }
        }
    }

    System.out.println("字符串中最长的颠倒字符串:"+maxstr1 + "," + maxstr2);
}

}

运行输出,字符串中最长的颠倒字符串:a123gh,hg321a

查看完整回答
反对 回复 2019-05-06
  • 6 回答
  • 0 关注
  • 477 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号