小编Dan*_*mel的帖子

detect duplicate character in string

I am doing the exercises in the Cracking The Coding Interview book and I am trying to determine if there is a duplicate character in a string. I am using the ArrayList data structure. My method is of return type Boolean, which returns true if there is a duplicate and returns false if there is no duplicate character. I added a third return statement so the program would compile but it always returns false.

import java.util.*;

public class QuestionOneCrackingCode { …
Run Code Online (Sandbox Code Playgroud)

java string arraylist char

7
推荐指数
3
解决办法
1万
查看次数

最小的普通多重可分

我正在使用JavaScript,我正在解决最小的公共倍数,两个数字,并且最小的公共倍数必须可以被两个数字之间的所有数字整除.

现在,我的代码根本不工作,没有返回任何内容.我有一个函数来计算最小公倍数和第二个函数来确定该倍数是否可被最小和最大数字之间的数字整除.

function smallestCommons(arr) {

    var max = 0;
    var min = 0;
    var lcm = 0;
    var max2 = 0;
       if(arr[0]> arr[1]) {
         max = arr[0];
         min = arr[1];
       } else {
         max = arr[1];
         min = arr[0];
       }

       function range(item){
         for(var j = min+1; j < max; j++){
           if(item % j !== 0){
             return 0;
           } else {
             return item;
           }
         }
       }   
       function lcmFind(min1, max1){
         for(var i =1; i < min1; i++){
             max1 = max1 * i; …
Run Code Online (Sandbox Code Playgroud)

javascript algorithm lcm

0
推荐指数
1
解决办法
1206
查看次数

标签 统计

algorithm ×1

arraylist ×1

char ×1

java ×1

javascript ×1

lcm ×1

string ×1