//compare参数实现,匿名函数lambda,这种比较方法的可行性ASCII码的比较,0对应dec的48 in ASCII中美国标准信息交换代码ANSI制定 string res; for(auto s:arr) res+=s; while(res[0]=='0' && res.length()>1) res.erase(0,1); /*erase函数的原型如下: (1)string& erase ( size_t pos = 0, size_...
GITHUB: https://github.com/yuzhangcmu/LeetCode_algorithm/blob/master/list/SortList.java
leetcode:合并链表 func addTwoNumbers(_ l1: ListNode?, _ l2: ListNode?) -> ListNode? { var tmp1 = l1 var tmp2 = l2 var stepper = 0 var destListNode: ListNode? while tmp1 != nil || tmp2 != nil { var dest = 0 if(tmp1 != nil){ dest = dest + tmp1!.val tmp1 = tmp1...
publicclassSort{publicstaticvoidmain(String[]args){int[]unsortedArray=newint[]{6,5,3,1,8,7,2,4};bubbleSort(unsortedArray);System.out.println("After sort: ");for(intitem:unsortedArray){System.out.print(item+" ");}}publicstaticvoidbubbleSort(int[]nums){intlen=nums.length;for(inti=0;...
[LeetCode] 451. Sort Characters By Frequency,Givenastring s,sortitindecreasingorderbasedonthefrequencyofcharacters,andreturn thesortedstring.Example1:Input:s="tree"Output:
Yu's garden Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue...