1
0

179.h 641 B

12345678910111213141516171819202122232425262728
  1. #include <stdlib.h>
  2. long cmp(int *x, int *y) {
  3. unsigned long sx = 10, sy = 10;
  4. while (sx <= *x) {
  5. sx *= 10;
  6. }
  7. while (sy <= *y) {
  8. sy *= 10;
  9. }
  10. return sx * (*y) + (*x) - sy * (*x) - (*y);
  11. }
  12. char *largestNumber(int *nums, int numsSize) {
  13. qsort(nums, numsSize, sizeof(int), cmp);
  14. if (nums[0] == 0) {
  15. char *ret = malloc(sizeof(char) * 2);
  16. ret[0] = '0', ret[1] = '\0';
  17. return "0";
  18. }
  19. char *ret = malloc(sizeof(char) * 1000);
  20. char *p = ret;
  21. for (int i = 0; i < numsSize; i++) {
  22. sprintf(p, "%d", nums[i]);
  23. p += strlen(p);
  24. }
  25. return ret;
  26. }
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。