首页下载资源后端java贪心算法的解题思路+代码

ZIPjava贪心算法的解题思路+代码

HD_132.09MB需要积分:1

资源文件列表:

贪心算法.zip 大约有162个文件
  1. .gitignore 538B
  2. day1/.idea/.gitignore 50B
  3. day1/.idea/misc.xml 276B
  4. day1/.idea/modules.xml 255B
  5. day1/.idea/vcs.xml 188B
  6. day1/.idea/workspace.xml 2.07KB
  7. day1/day1.iml 433B
  8. day1/pom.xml 665B
  9. day1/src/Main.java 2.27KB
  10. day10/.idea/.gitignore 50B
  11. day10/.idea/misc.xml 276B
  12. day10/.idea/modules.xml 257B
  13. day10/.idea/vcs.xml 188B
  14. day10/.idea/workspace.xml 1.88KB
  15. day10/day10.iml 433B
  16. day10/src/Main.java 1.59KB
  17. day11/.idea/.gitignore 50B
  18. day11/.idea/misc.xml 276B
  19. day11/.idea/modules.xml 257B
  20. day11/.idea/vcs.xml 188B
  21. day11/.idea/workspace.xml 2.79KB
  22. day11/day11.iml 433B
  23. day11/out/production/day11/Main.class 1014B
  24. day11/src/Main.java 1.97KB
  25. day12/.idea/.gitignore 50B
  26. day12/.idea/misc.xml 276B
  27. day12/.idea/modules.xml 257B
  28. day12/.idea/vcs.xml 188B
  29. day12/.idea/workspace.xml 1.88KB
  30. day12/day12.iml 433B
  31. day12/src/Main.java 1.05KB
  32. day13/.idea/.gitignore 50B
  33. day13/.idea/misc.xml 276B
  34. day13/.idea/modules.xml 257B
  35. day13/.idea/vcs.xml 188B
  36. day13/.idea/workspace.xml 1.88KB
  37. day13/day13.iml 433B
  38. day13/src/Main.java 772B
  39. day14/.idea/.gitignore 50B
  40. day14/.idea/misc.xml 276B
  41. day14/.idea/modules.xml 257B
  42. day14/.idea/vcs.xml 188B
  43. day14/.idea/workspace.xml 2.08KB
  44. day14/day14.iml 433B
  45. day14/out/production/day14/Main.class 1.1KB
  46. day14/src/Main.java 1.21KB
  47. day15/.idea/.gitignore 50B
  48. day15/.idea/misc.xml 276B
  49. day15/.idea/modules.xml 257B
  50. day15/.idea/vcs.xml 188B
  51. day15/.idea/workspace.xml 2.61KB
  52. day15/day15.iml 433B
  53. day15/out/production/day15/Main.class 1.47KB
  54. day15/src/Main.java 1.87KB
  55. day16/.idea/.gitignore 50B
  56. day16/.idea/misc.xml 276B
  57. day16/.idea/modules.xml 257B
  58. day16/.idea/vcs.xml 188B
  59. day16/.idea/workspace.xml 2.71KB
  60. day16/day16.iml 433B
  61. day16/out/production/day16/Main.class 1.44KB
  62. day16/src/Main.java 861B
  63. day17/.idea/.gitignore 50B
  64. day17/.idea/misc.xml 276B
  65. day17/.idea/modules.xml 257B
  66. day17/.idea/vcs.xml 188B
  67. day17/.idea/workspace.xml 2.91KB
  68. day17/day17.iml 433B
  69. day17/out/production/day17/Main.class 1.65KB
  70. day17/src/Main.java 1.91KB
  71. day18/.idea/.gitignore 50B
  72. day18/.idea/misc.xml 276B
  73. day18/.idea/modules.xml 257B
  74. day18/.idea/vcs.xml 188B
  75. day18/.idea/workspace.xml 2.35KB
  76. day18/day18.iml 433B
  77. day18/out/production/day18/Main.class 976B
  78. day18/src/Main.java 1.24KB
  79. day19/.idea/.gitignore 50B
  80. day19/.idea/misc.xml 276B
  81. day19/.idea/modules.xml 257B
  82. day19/.idea/vcs.xml 188B
  83. day19/.idea/workspace.xml 1.99KB
  84. day19/day19.iml 433B
  85. day19/src/Main.java 503B
  86. day2/.idea/.gitignore 50B
  87. day2/.idea/inspectionProfiles/Project_Default.xml 276B
  88. day2/.idea/misc.xml 276B
  89. day2/.idea/modules.xml 255B
  90. day2/.idea/vcs.xml 188B
  91. day2/.idea/workspace.xml 2.98KB
  92. day2/day2.iml 433B
  93. day2/out/production/day2/Imp.class 1.19KB
  94. day2/out/production/day2/Main.class 1.12KB
  95. day2/src/Main.java 1.25KB
  96. day3/.idea/.gitignore 50B
  97. day3/.idea/misc.xml 276B
  98. day3/.idea/modules.xml 255B
  99. day3/.idea/vcs.xml 188B
  100. day3/.idea/workspace.xml 2.06KB
  101. day3/day3.iml 433B
  102. day3/src/Main.java 1.26KB
  103. day4/.idea/.gitignore 50B
  104. day4/.idea/misc.xml 276B
  105. day4/.idea/modules.xml 255B
  106. day4/.idea/vcs.xml 188B
  107. day4/.idea/workspace.xml 2.06KB
  108. day4/day4.iml 433B
  109. day4/src/Main.java 1.37KB
  110. day5/.idea/.gitignore 50B
  111. day5/.idea/misc.xml 276B
  112. day5/.idea/modules.xml 255B
  113. day5/.idea/vcs.xml 188B
  114. day5/.idea/workspace.xml 1.99KB
  115. day5/day5.iml 433B
  116. day5/src/Main.java 1.72KB
  117. day6/.idea/.gitignore 50B
  118. day6/.idea/misc.xml 276B
  119. day6/.idea/modules.xml 255B
  120. day6/.idea/vcs.xml 188B
  121. day6/.idea/workspace.xml 1.99KB
  122. day6/day6.iml 433B
  123. day6/src/Main.java 2.48KB
  124. day7/.idea/.gitignore 50B
  125. day7/.idea/misc.xml 276B
  126. day7/.idea/modules.xml 255B
  127. day7/.idea/vcs.xml 188B
  128. day7/.idea/workspace.xml 1.99KB
  129. day7/day7.iml 433B
  130. day7/src/Main.java 811B
  131. day8/.idea/.gitignore 50B
  132. day8/.idea/misc.xml 276B
  133. day8/.idea/modules.xml 255B
  134. day8/.idea/vcs.xml 188B
  135. day8/.idea/workspace.xml 1.88KB
  136. day8/day8.iml 433B
  137. day8/src/Main.java 808B
  138. day9/.idea/.gitignore 50B
  139. day9/.idea/misc.xml 276B
  140. day9/.idea/modules.xml 255B
  141. day9/.idea/vcs.xml 188B
  142. day9/.idea/workspace.xml 1.88KB
  143. day9/day9.iml 433B
  144. day9/src/Main.java 917B
  145. 贪心算法day12.png 124.73KB
  146. 贪心算法day13.png 161.07KB
  147. 贪心算法练习14.png 134.4KB
  148. 贪心算法练习day10.png 187.51KB
  149. 贪心算法练习day11.png 186.42KB
  150. 贪心算法练习day15.png 179.6KB
  151. 贪心算法练习day16.png 90.96KB
  152. 贪心算法练习day17.png 138.23KB
  153. 贪心算法练习day18.png 145.33KB
  154. 贪心算法练习day2.png 98.21KB
  155. 贪心算法练习day3.png 182.82KB
  156. 贪心算法练习day4.png 224.34KB
  157. 贪心算法练习day5.png 203.19KB
  158. 贪心算法练习day6.png 192.76KB
  159. 贪心算法练习day7.png 93.68KB
  160. 贪心算法练习day8.png 119.15KB
  161. 贪心算法练习day9.png 134.02KB
  162. 贪心算练习day1.png 171.14KB

资源介绍:

内容概要 在这篇文章中,我详细介绍了贪心算法的基本概念和常用策略,并通过多个经典的实际例子展示了贪心算法在解决各种问题中的应用。您将学习到: 贪心算法的核心思想和特点。 如何识别和设计贪心策略以解决特定问题。 使用Java编程语言实现贪心算法的具体代码示例。 对不同问题的优化思路和代码实现过程的详细解析。 适用人群 这篇文章适合以下几类人群: 编程初学者:希望了解并掌握贪心算法的基本概念和实现方法。 计算机科学专业学生:正在学习算法课程并需要更多实际例子的同学。 软件开发人员:需要在项目中应用贪心算法解决具体问题的工程师。 算法爱好者:对算法研究感兴趣并希望深入理解贪心算法的朋友。 使用场景 这篇文章适用于多种学习和工作场景,包括但不限于: 算法学习和复习:作为学习贪心算法的重要参考资料,帮助您巩固和提升算法知识。 编程面试准备:为准备编程面试的您提供具体的解题思路和代码实现,帮助您应对算法相关的面试题目。 项目开发实践:在实际项目中需要使用贪心算法时,提供可直接应用的代码示例和优化方案。 希望这篇文章能为您提供实用的帮助和启发,欢迎阅读并分享您的宝贵意见! 祝学习愉快!
import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.Map; /** * Created with IntelliJ IDEA. * Description: * User: 周斌 * Date: 2024-05-13 * Time: 17:03 */ public class Main { //day6 排序 力扣2418 按身高排序 //方法一:利用哈希存下映射关系 public String[] sortPeople(String[] names, int[] heights) { //1.先用map将身高与名字建立映射关系 Map map = new HashMap<>(); int n = names.length; for (int i = 0; i < n; i++) { map.put(heights[i], names[i]); } //2.对身高进行排序 Arrays.sort(heights); //通过map将身高排序后对应的名字提取出来 int index = 0; String[] str = new String[n]; for(int i = heights.length-1;i >= 0;i--) { str[index++] = map.get(heights[i]); } return str; } //方法二:对下标进行排序(不改变数组中的元素位置) public String[] sortPeople1(String[] names, int[] heights) { int n = names.length; // 1.创建下标数组 Integer[] index = new Integer[n]; for (int i = 0; i < n; i++) { index[i] = i; } // 2.对下标数组排序(排序的规则是根据身高数组降序) Arrays.sort(index, (i, j) -> { return heights[j] - heights[i]; }); // 3.遍历下标数组的值作为names数组的下标传给新数组 String[] str = new String[n]; for (int i = 0; i < n; i++) { str[i] = names[index[i]]; } return str; } //day6 贪心算法练习870力扣 优势洗牌 public int[] advantageCount(int[] nums1, int[] nums2) { // 1.排序 Arrays.sort(nums1); int n = nums1.length; Integer[] index2 = new Integer[n]; for (int i = 0; i < n; i++) { index2[i] = i; } Arrays.sort(index2, (i, j) -> { return nums2[i] - nums2[j]; }); // 2.比较 int left = 0, right = n - 1; int[] ret = new int[n]; for (int i = 0; i < n; i++) { if (nums1[i] > nums2[index2[left]]) { ret[index2[left]] = nums1[i]; left++; } else { ret[index2[right]] = nums1[i]; right--; } } return ret; } }
100+评论
captcha