(1) 有一个长度为100的数组,其中每个元素都大于0,小于等于100,请写一函数,判断数组是否存在值相等的元素
(2) 写一函数,返回二叉树中等于某值的元素
(3) 写一函数,返回某数组各元素升序排序后的位置,如数组为(8,5,7,6),则该函数返回(4,1,3,2)
(4) 有一天平和一13克的砝码,如果将该砝码摔成3瓣,请问当这3瓣分别是多少克的情况下,该天平可以秤出重量为1至13整数克的任何物体
1.
public boolean checkSameItem(int[]intArr){ Arrays.sort(intArr); for (int i = 0; i < intArr.length -1; i++) { if (intArr[i] ==intArr[i+1]) { return Boolean.TRUE; } } return Boolean.FALSE; }
2. 没怎么看懂你的返回,写一个递归基本就可以完成对树的遍历
3.
public int[] getIndexArr(int[]intArr) { int[]copyArr = Arrays.copyOf(intArr, intArr.length); Arrays.sort(copyArr); int []retArr = new int[4]; for (int i = 0; i < intArr.length; i++) { retArr[i] = Arrays.binarySearch(copyArr, intArr[i]) + 1; } return retArr; }
4. 1,3,9
(3)
private static int[] getAscendingIndex(int[] array) { int[] indexArray = new int[array.Length]; for (int i = 0; i < array.Length; i++) { int index = 0; for (int j = 0; j < array.Length; j++) { if (array[j]<= array[i]) { index++; } } indexArray[i] = index; } return indexArray; }
(2)
BiTree* BiTree Findpoint(BiTree T,char e) { if(T&&T->ch == e) return e; if(T==NULL) return NULL; if(T->lchild) return Findpoint(T->lchild,e); else if(T->rchild ) return Findpoint(T->rchild,e); }
(4) 1,3,9
(2) 返回值和返回类型错误
(3) 效率为n^2 ,但是可以用n*log(n)效率做
第一题,https://www.cnblogs.com/JiYF/p/8799492.html
http://gacha.163.com/subject/detail/49823424fd854da2814e531a1b9624c8
http://gacha.163.com/subject/detail/2bf5712cd99c4941a958269ed190b78b
http://gacha.163.com/subject/detail/337fa58f0cdf4a6687ad62474c1a7174
http://gacha.163.com/subject/detail/6af28b0d83b448df8724ba4fd6eae609
http://gacha.163.com/subject/detail/9717473bf23645129d89d4efa21e9c53
http://gacha.163.com/subject/detail/e0310aef90bb4031b87b735a60d9ddd8
http://gacha.163.com/subject/detail/f7c12c2582b84fe280307be8bdc9342b
http://gacha.163.com/subject/detail/8fb7c381c7674f90854c502327cf34fb
http://gacha.163.com/subject/detail/6f7ec3660e3f4c688f8c24a067da88cb
http://gacha.163.com/subject/detail/49b2a73cff1145eca2c6d413100dd06c
http://gacha.163.com/subject/detail/e192dedb72db4a688826634b56625162
http://gacha.163.com/subject/detail/9ac8325ef5354bb8b9e556cc2a6f44a5
http://gacha.163.com/subject/detail/a768c0650d6a480dac1e555983178ee0
http://gacha.163.com/subject/detail/9178e4ae5658416cb9750229efd9e0d8
http://gacha.163.com/subject/detail/a2c18c304f524df78ad151cc3b3c2cf3
http://gacha.163.com/subject/detail/b0a38c9002c24bdabca2b44039f7a6eb
http://gacha.163.com/subject/detail/2a0da8d027cf4b9a9dab774ef76911a3
http://gacha.163.com/subject/detail/61d4bc72bda649bc8343b4c4e05c0969
http://gacha.163.com/subject/detail/cf33e0a282b748c6b22a2c0664fcc041
http://gacha.163.com/subject/detail/d6e5ad0cf8f04a159eb124e3e2bdaeb8
http://gacha.163.com/subject/detail/244fc9130b284b1ca04282514a7eafa4
http://gacha.163.com/subject/detail/9a7eefbeda4048d8a9cf1d4f64828a18
http://gacha.163.com/subject/detail/65a25172c0bf4d48ae4a0d1f84c13740
http://gacha.163.com/subject/detail/9a6fd899fbdb42fab849f70a02b9cb4c
http://gacha.163.com/subject/detail/4d9fedb762a54db2bf8e73f7fd60a60b
http://gacha.163.com/subject/detail/6e2fd6aa83a3470a8c21f407f270a98c
http://gacha.163.com/subject/detail/7b8af34f4d4447d58eae058eeda76c26
http://gacha.163.com/subject/detail/984a4637b9414ee3bce520f19ff6ddb1