方法一:分治 + 递归 解题思路 在21. 合并两个有序链表,我们知道如何合并两个有序链表.而本题是合并 k 个有序链表,可以通过大问题拆分成小问题解决,即把 k 个链表,拆分成 k/2 个链表组,俩俩合并,直到合并成一个链表,这就是分而治之的思想. 可以通过递归来实现分治算法: 定义函数功能:合并链表数组中的 left 到 right 个链表 结束条件:left == right,即只剩下一个链表,无须合并,直接返回 递推公式:将 [left, right] 拆分成两半,分别获得左边已合并的链…
leetcode - 39. Combination Sum - Medium descrition Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from…
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion d…
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, which means you have to modify the input 2D matrix direct…
leetcode - 31. Next Permutation - Medium descrition Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible…
Leetcode 67:Add Binary(二进制求和) (python.java) Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. 给定两个二进制字符串,返回他们的和(用二进制表示). 输入为非空字符串且只包含数字 1 和 0. Example 1: Input…
我被这些题整哭了,你呢??? 日了狗啊...... 好难啊.... 按照这个样子搞,不用找工作了,回家放牛去....... package y2019.Algorithm.divideandconquer.medium; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.divideandconquer.medium * @ClassName: FindKthLargest * @Author: xiaof * @Descr…
今天的字符类还比较简单 package y2019.Algorithm.str.easy; import java.util.HashMap; import java.util.Map; import java.util.Stack; /** * @ClassName IsValid * @Description 20. Valid Parentheses * * Given a string containing just the characters '(', ')', '{', '}',…
package y2019.Algorithm.LinkedList.medium; import y2019.Algorithm.LinkedList.ListNode; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.LinkedList.medium * @ClassName: AddTwoNumbers * @Author: xiaof * @Description: TODO 2. Add Two Numbers…
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天我们讲的是LeetCode的31题,这是一道非常经典的问题,经常会在面试当中遇到.在今天的文章当中除了关于题目的分析和解答之外,我们还会详细解读深度优先搜索和回溯算法,感兴趣的同学不容错过. 链接 Next Permutation 难度 Medium 描述 实现C++当中经典的库函数next permutation,即下一个排列.如果把数组当中的元素看成字典序的话,那下一个排列即是字典序比当前增加1的排列.如果已经是字典序最大的情况…