摘要:
全排列(046) class Solution { List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>> permute(int[] nums) { int n = nums.length; List<Inte 阅读全文
摘要:
岛屿数量(200) class Solution { public int numIslands(char[][] grid) { int res = 0; int m = grid.length; int n = grid[0].length; for (int i = 0; i < m ; i+ 阅读全文
摘要:
二叉树的右视图(199) class Solution { List<Integer> res = new ArrayList<>(); public List<Integer> rightSideView(TreeNode root) { dfs(root, 0); return res; } p 阅读全文
摘要:
二叉树的中序队列(094) 先看代码 class Solution { public List<Integer> inorderTraversal(TreeNode root) { List<Integer> res = new ArrayList<>(); Stack<TreeNode> stac 阅读全文
摘要:
K个一组翻转链表(025) 先看代码 class Solution { public ListNode reverseKGroup(ListNode head, int k) { ListNode dummy = new ListNode(-1, head); ListNode prev = dum 阅读全文
摘要:
相交链表(160) 先看代码 public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { ListNode p = headA; ListNode q = headB; w 阅读全文
摘要:
矩阵置零(073) 先看代码 class Solution { public void setZeroes(int[][] matrix) { boolean col0_flag = false; int row = matrix.length; int col = matrix[0].length 阅读全文
摘要:
最大子数组和(053) 先看代码 class Solution { public int maxSubArray(int[] nums) { int n = nums.length; int subSum = 0; int res = nums[0]; for (int i = 0; i < n; 阅读全文
摘要:
和为K的子数组(560) 先看代码 class Solution { public int subarraySum(int[] nums, int k) { int res = 0; int preSum = 0; Map<Integer, Integer> cnt = new HashMap<>( 阅读全文