dedecms 资源类网站wordpress发文章后显示两篇
web/
2025/10/2 1:03:11/
文章来源:
dedecms 资源类网站,wordpress发文章后显示两篇,有哪些平台可以发布推广信息,网站公司的好坏描述 判断两个字符串是否由相同的字符组成 分析 方法一#xff0c;排序法。对两个字符串进行排序#xff0c;然后在比较。 方法二#xff0c;空间换时间。ascII字符共256个#xff0c;对字符串1出现的字符在对应的数组里加1#xff0c;对字符串1出现的字符在对应的数组里减…描述 判断两个字符串是否由相同的字符组成 分析 方法一排序法。对两个字符串进行排序然后在比较。 方法二空间换时间。ascII字符共256个对字符串1出现的字符在对应的数组里加1对字符串1出现的字符在对应的数组里减1。 代码 方法一 排序法。 public class Test {public static boolean compare(String s1,String s2){if(s1.length()!s2.length()) return false;byte[] byte1s1.getBytes();byte[] byte2s2.getBytes();Arrays.sort(byte1);Arrays.sort(byte2);for(int i0;is1.length();i){if(byte1[i]!byte2[i]) return false;}return true;}public static void main(String[] args) {System.out.println(compare(zayyyy,zayyyy));}
} 方法二空间换时间。 public class Test {public static boolean compare(String s1,String s2){if(s1.length()!s2.length()) return false;byte[] byte1s1.getBytes();byte[] byte2s2.getBytes();int[] charCountnew int[256]; //ascII 字符共有266个。for(int i0;is1.length();i){charCount[byte1[i]];charCount[byte2[i]]--;}for(int i:charCount){if(i!0) return false;}return true;}public static void main(String[] args) {System.out.println(compare(zayyyy,zayyyb));}
} 转载于:https://www.cnblogs.com/zadomn0920/p/6358255.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/85343.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!