问题 Given a triangle array, return the minimum path sum from top to bottom.
For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.
问题 You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.
classSolution { List<List<Integer>> ans; public List<List<Integer>> combine(int n, int k) { ans = newArrayList<>(); backTrack(newLinkedList(),1,n,k); return ans; } privatevoidbackTrack(LinkedList<Integer> list, int start, int n, int k){ if (k == 0){ ans.add(newArrayList(list)); return; }
for (inti= start; i <= n-k+1; i++){ list.add(i); backTrack(list, i+1, n, k-1); list.removeLast(); } } }
问题 According to Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”
The board is made up of an m x n grid of cells, where each cell has an initial state: live (represented by a 1) or dead (represented by a 0). Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article):
Any live cell with fewer than two live neighbors dies as if caused by under-population.
Any live cell with two or three live neighbors lives on to the next generation.
Any live cell with more than three live neighbors dies, as if by over-population.
Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
The next state is created by applying the above rules simultaneously to every cell in the current state, where births and deaths occur simultaneously. Given the current state of the m x n grid board, return the next state.
问题 You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:
/* // Definition for a Node. class Node { public int val; public Node left; public Node right; public Node next; public Node() {} public Node(int _val) { val = _val; } public Node(int _val, Node _left, Node _right, Node _next) { val = _val; left = _left; right = _right; next = _next; } }; */
classSolution { public Node connect(Node root) { if (root==null){return root;} if (root.right!=null){ root.left.next = root.right; if (root.next!=null){ root.right.next = root.next.left; } } connect(root.left); connect(root.right); return root; } }
You are given an m x n binary matrix grid. An island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
The area of an island is the number of cells with a value 1 in the island.
Return the maximum area of an island in grid. If there is no island, return 0.