C++ 剑指offer
剑指offer
失落的换海迷风
关注我了解最近咨询
展开
-
[剑指 Offer 47.] 礼物的最大价值
一.题目描述在一个 m*n 的棋盘的每一格都放有一个礼物,每个礼物都有一定的价值(价值大于 0)。你可以从棋盘的左上角开始拿格子里的礼物,并每次向右或者向下移动一格、直到到达棋盘的右下角。给定一个棋盘及其上面的礼物的价值,请计算你最多能拿到多少价值的礼物?https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/ 二.代码class Solution {public: int maxValue(vector<原创 2021-02-20 23:02:21 · 71 阅读 · 0 评论 -
[剑指 Offer 46.] 把数字翻译成字符串
一.题目给定一个数字,我们按照如下规则把它翻译为字符串:0 翻译成 “a” ,1 翻译成 “b”,……,11 翻译成 “l”,……,25 翻译成 “z”。一个数字可能有多个翻译。请编程实现一个函数,用来计算一个数字有多少种不同的翻译方法https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/ 二.代码class Solution {public: int translateNum(int原创 2021-02-19 22:30:35 · 59 阅读 · 0 评论 -
[剑指 Offer 45.] 把数组排成最小的数
一.题目输入一个非负整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/ 二.代码class Solution {public: string minNumber(vector<int>& nums) { vector<string> strs;原创 2021-02-19 22:06:14 · 57 阅读 · 0 评论 -
【力扣】[剑指 Offer 29.] 顺时针打印矩阵
一.题目输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字。链接:https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof/二.代码展示/** * Note: The returned array must be malloced, assume caller calls free(). */int* spiralOrder(int** matrix, int matrixSize, int* matri原创 2020-09-17 12:24:56 · 96 阅读 · 0 评论 -
【力扣】[剑指 Offer 05.] 替换空格
一.题目请实现一个函数,把字符串 s 中的每个空格替换成"%20"。链接:https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/二.代码展示class Solution {public: string replaceSpace(string s) { // 原来s的下标 int size1 = s.length() - 1; // 遇到空格,就在后面+=00 for(int原创 2020-08-07 09:13:41 · 164 阅读 · 0 评论 -
【力扣】[剑指 Offer 04] 二维数组中的查找
一.题目在一个 n * m的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。链接:https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/class Solution {public: bool findNumberIn2DArray(vector<vector<int>&g原创 2020-08-06 14:29:30 · 125 阅读 · 0 评论 -
【力扣】[剑指offer03]数组中重复的数字
找出数组中重复的数字。在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。链接:https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/方法一:排序算法class Solution {public: int findRepeatNumber(vector<int&g.原创 2020-08-04 08:58:14 · 122 阅读 · 0 评论