摘要:
class Solution { public List<List<Integer>> generate(int numRows) { // 初始化结果列表,用于存储杨辉三角的每一行 List<List<Integer>> ret = new ArrayList<List<Integer>>(); 阅读全文
摘要:
class Solution { public int climbStairs(int n) { // 使用三个变量进行状态转移: // p 表示到达前两个台阶的方法数 // q 表示到达前一个台阶的方法数 // r 表示当前台阶的方法数 int p = 0, q = 0, r = 1; // 遍历 阅读全文
摘要:
class Solution { public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> result = new ArrayList<>(); Arrays.sort(nums); // 先对数组排序,便于使用双指 阅读全文
摘要:
class Solution { // 移动零到数组末尾,同时保持非零元素的原有顺序 public void moveZeroes(int[] nums) { int n = nums.length; // 数组长度 int left = 0, right = 0; // 双指针:left指向待替换 阅读全文
摘要:
public int maxArea(int[] height) { // 初始化最大盛水量为0 int res = 0; // 使用双指针,i从数组起始位置开始,j从数组末尾开始 int i = 0; int j = height.length - 1; // 双指针向中间移动,直到相遇 whil 阅读全文