Print Binary Tree 按照要求输出二叉树在对应二维数组种的值 /** * Definition for a binary tree node. * public class TreeNode { * pub…
标签:LeetCode swift
算法: reshape the matrix
reshape the matrix // 找到对应新矩阵和原来矩阵行列的关系以及对应的变换 // class Solution { func matrixReshape(_ nums: [[Int]], _ r: In…
c语言 递归实现八皇后算法
#include <stdio.h> #include <stdlib.h> int count; //递归法实现八皇后问题 //参数row表示起始行,参数n表示列数 //参数(*chess)[8…
算法: Hamming Distance
Hamming Distance 计算两个二进制数中 对应位上不同的数字总数 class Solution { func hammingDistance(_ x: Int, _ y: Int) -> Int { v…
算法: Dungeon Game
Dungeon Game 计算出二维数组从0.0 点到 m.n 点的最小代价.. 并且每经过一个格子所剩余的代价必须是> 0 的 class Solution { public: int calculateMini…
KMP 算法实践
很多不理解. 先背下来吧 void get_next(String T, int *next) { int i , j; next[0] = 1; i = 1; j = 0; while (i < T.size()…
算法: Sum of left Leaves
Sum of left Leaves 计算二叉树种所有叶子左叶子节点的值的总合 /** * Definition for a binary tree node. * public class TreeNode { * p…
算法: Assign cookies
Assign Cookies class Solution { func findContentChildren(_ g: [Int], _ s: [Int]) -> Int { var gg = g.sorted…
算法: 数组种的逆序对
题目: 在数组中的两个数字如果前面一个数字大于后面的数字,则这两 个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数。 例如在数组{7,5,6,4} 中,一一共存在5 个逆序对,分别是(7,6)、(7,5)…
算法:字符串中第一个只出现一次的字符
题目: 在字符串种找出第一个只出现一次的字符, 如”abaccgagg” 则输出”b” 参考代码如下 时间负责度 为 O(n) class solution { // 利用…
Swift LeetCode 系列之48:rotate-image
https://leetcode.com/problems/rotate-image/description/ 沿着副对角反转一次. 在沿着水平线翻转一次即可 class Solution { func rotate(_…
Swift LeetCode 系列之46: permutations
https://leetcode.com/problems/permutations/description/ 笨方法采用了递归的方式 class Solution { var res = [[Int]]() var n…