вторник, 2 августа 2022 г.

Buuble Sort Java Script. Leetcode 75. Sort Colors


https://leetcode.com/problems/sort-colors/


 var sortColors = function(nums) {
    
    for(i=0; i<nums.length; i++){
    
        for(k=0; k<(nums.length - i); k++){
            if(nums[k] > nums[k+1]){
                let temp = nums[k]
                nums[k] = nums[k+1]
                nums[k+1] = temp
            }
        }
        
    }
};

четверг, 28 июля 2022 г.

Kotlin Bubble sort. Leetcode 75. Sort Colors

 class Solution {
    
    fun sortColors(nums: IntArray): Unit {
        
        for (z in 0..(nums.size-1)){
            var sizes:Int = nums.size
            for (iterationNumber in 1..nums.size - z){
                if ( iterationNumber == nums.size){
                    break
                }
                val indexOne:Int = iterationNumber - 1
                val indexTwo:Int = iterationNumber
                if (nums[indexOne] > nums[indexTwo]){
                    val saved = nums[indexTwo]
                    nums[indexTwo] = nums[indexOne]
                    nums[indexOne] = saved         
                }
                // print(iterationNumber)
            }
         }
    }
}


75. Sort Colors
https://leetcode.com/problems/sort-colors/


Bubble Sort Visualizer
https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/visualize/