01 2019 档案
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) OJ编程实例 给定一棵二叉树的前序(根、左、右)和中序(左、根、右)的打印结果,输出此二叉树按层(从左往右)打印结果。 例如一棵二叉树前序:1 2 4 5 3;中序:4 2 5 1 3。可以构建出下图所示二叉树: 按层打印的
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 笔试中的编程题一般用OJ平台(如牛客网),而这些平台绝大部分都会要求自己写输入部分(不同于leetcode),如果对输入部分不熟悉的话会浪费很多时间,所以这一部分需熟练掌握。 输入问题 1 整数输入问题 //参考博文:ACM
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 本文转载自博客:https://blog.csdn.net/JNingWei/article/details/78425824 博客内容如下: 原 OJ术语: AC、WA、TLE、OLE、MLE、RE、PE、CE 2017年
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Shuffle an Array Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. in
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Fizz Buzz Write a program that outputs the string representation of numbers from 1 to n. But for multiples of th
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 231. Power of Two Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 O
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 64 求1+2+...+n 题目描述 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。 /* 方法一:利用函数指针 用!!n选择函
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 65 不用加减乘除做加法 题目描述 写一个函数,求两个整数之和,要求在函数体内不得使用+、-、*、/四则运算符号。 /* 用三步走的方式计算二进制值相加: 5-101,7-111 第一步:相加各位的值,不算进位,得到010,
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 62 圆圈中最后剩下的数字(约瑟夫环问题) 题目描述 每年六一儿童节,牛客都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此。HF作为牛客的资深元老,自然也准备了一些小游戏。其中,有个游戏是这样的:首先,让小朋友们围成一个
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 17 打印从1到最大的n位数 题目:输入数字n,按顺序打印出从1最大的n位十进制数。比如输入3,则打印出1、2、3一直到最大的3位数即999. 解题思路: (1) 此题需要考虑大数问题,n位数用整型(int)或者长整型(lo
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 43 n个骰子的点数 题目: 把n个骰子仍在地上,所有骰子朝上一面的点数之和为s。输入n,打印出s的所有可能的值出现的概率。 思路: s可能出现的值的范围为:n--6*n 1、全排列 回溯法枚举n个骰子(6面)的全排列,然后
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Sqrt(x) Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to be a non-ne
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 50. Pow(x, n) Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 53. Maximum Subarray Given an integer array nums, find the contiguous subarray (containing at least one number)
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Number of Islands Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Subsets Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Letter Combinations of a Phone Number Given a string containing digits from 2-9 inclusive, return all possible l
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 13 机器人的运动范围 题目描述 地上有一个m行和n列的方格。一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和大于k的格子。 例如,当k为18时,机器人能
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Generate Parentheses Given n pairs of parentheses, write a function to generate all combinations of well-formed
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 12 矩阵中的字符串查找(79. Word Search 系列) Word Search Given a 2D board and a word, find if the word exists in the grid. T
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 排列与组合 说明:排列组合方法很多,不限于文中的这些方法,可以在网上多看些解法,选择几种自己比较欣赏的解法。 1 Permutations I Given a collection of distinct integers,
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 背包问题总结 背包问题 背包问题 (Knapsack problem x ) 有很多种版本,常见的是以下三种: 0-1 背包问题 (0-1 knapsack problem):每种物品只有一个 完全背包问题 (UKP, un
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Word Break(系列) Word Break Given a non-empty string s and a dictionary wordDict containing a list of non-empty wo
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Burst Balloons Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Coin Change(系列) Coin Change You are given coins of different denominations and a total amount of money amount. W
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Jump Game(系列) Jump Game Given an array of non-negative integers, you are initially positioned at the first index
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Best Time to Buy and Sell Stock(系列) 121. Best Time to Buy and Sell Stock Say you have an array for which the ith
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest increasing subseq
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Unique Paths(系列) Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the d
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) House Robber(系列) House Robber You are a professional robber planning to rob houses along a street. Each house ha
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 47:礼物的最大价值 题目: 在一个m*n的棋盘的每一格都放有一个礼物,每个礼物都有一定的价值(价值大于0)。你可以从棋盘的左上角开始拿格子里的礼物,并每次向左或者向下移动一格,直到到达棋盘的右下角。给定一个棋盘及其上面的礼
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 《算法导论》动态规划、贪婪法与分治法ppt 对于学算法的同学,推荐经典书籍《算法导论》,这本书还有配套的视频(见参考链接),是MIT的教授主讲的,听完特别有收获,下面为博主在学习算法设计技巧时看的几个内容,附上对应的ppt,
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Maximum Product Subarray Given an integer array nums, find the contiguous subarray within an array (containing a
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 53. Maximum Subarray Given an integer array nums, find the contiguous subarray (containing at least one number)
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 剑指Offer-46:把数字翻译成字符串 题目: 给定一个数字,我们按照如下规则把它翻译为字符串:0翻译成“a”,1翻译成“b”,……,11翻译成“1”,……,25翻译成“z”。一个数字可能有多个翻译。例如:12258有5种
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 14 剪绳子 题目:给你一根长度为n的绳子,请把绳子剪成m段 (m和n都是整数,n>1并且m>1)每段绳子的长度记为k[0],k[1],...,k[m].请问k[0]*k[1]*...*k[m-1]可能的最大乘积是多少? 例
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 70. Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you can eithe
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Wiggle Sort II Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... Exam
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Merge Intervals Given a collection of intervals, merge all overlapping intervals. Example 1: Input: [[1,3],[2,6]
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Top K Frequent Elements Given a non-empty array of integers, return the k most frequent elements. For example, G
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Sort Colors Given an array with n objects colored red, white or blue, sort them in-place so that objects of the
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) First Bad Version You are a product manager and currently leading a team to develop a new product. Unfortunately
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Find Peak Element A peak element is an element that is greater than its neighbors. Given an input array nums, wh
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Search for a Range Given an array of integers nums sorted in ascending order, find the starting and ending posit
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 153. Find Minimum in Rotated Sorted Array Suppose an array sorted in ascending order is rotated at some pivot un
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 33. Search in Rotated Sorted Array Suppose an array sorted in ascending order is rotated at some pivot unknown t
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Merge Sorted Array Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 41 数据流中的中位数 题目描述 如何得到一个数据流中的中位数?如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值。如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两个数的平均值。 /
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the m
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 40 最小的k个数 题目描述 输入n个整数,找出其中最小的K个数。例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4, /* //暴力法:sort, O(nlogn) //方法一:使用自带的s
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 二分查找小结 /* 类型1 功能:查找和目标值完全相等的数 返回:如果存在,返回对应位置索引,否则返回-1 例: [2, 4, 5, 6, 9],target = 6,返回索引3 */ int find(vector<int
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 8 二叉树中序遍历的下一个结点 题目描述 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。 分析: 结合图,我们可发现分成两大类: (1)
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLi
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Kth Smallest Element in a BST Given a binary search tree, write a function kthSmallest to find the kth smallest
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, convert
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 36 二叉搜索树与双向链表 题目描述 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。 /* struct TreeNode { int val; struc
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 33 判断某序列是否为二叉搜索树的后序序列 题目描述 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。 /* 后序遍历序列规律:最后一
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Validate Binary Search Tree Validate Binary Search Tree Given a binary tree, determine if it is a valid binary s
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 297. Serialize and Deserialize Binary Tree Serialization is the process of converting a data structure or object
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 105. Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree, c
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 124. Binary Tree Maximum Path Sum Given a non-empty binary tree, find the maximum path sum. For this problem, a
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 572. Subtree of Another Tree Given two non-empty binary trees s and t, check whether tree t has exactly the same
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 112. Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up a
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 27 二叉树的镜像 题目描述 操作给定的二叉树,将其变换为源二叉树的镜像。 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ 1
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 101. Symmetric Tree /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; *
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 110. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a height-ba
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the number o
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 68 树中两个节点的最低公共祖先 题目: 求树中两个结点的最低公共祖先 思路: 考虑一下几种情况: 1、该树为二叉搜索树 二叉搜索树是排序树,位于左子树点的结点都比父结点小,而位于右子树的结点都比父结点大,只需要从树的根结点
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 二叉查找树的查找、插入、删除 1 查找结点 最佳情况是 O(log2n),而最坏情况是 O(n) BST 的查找是从根结点开始,若二叉树非空,将给定值与根结点的关键字比较, 若相等,则查找成功; 若不等,则比较查找结点值与
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 二叉树的遍历总结 (前序、中序、后序、层序、 之字形层序、垂直遍历) 三种递归遍历 //前序遍历(根-左-右) void preorder(TreeNode *root, vector<int> &path) { if(ro
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Palindrome Linked List Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Outpu
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Add Two Numbers You are given two non-empty linked lists representing two non-negative integers. The digits are
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 328. Odd Even Linked List Given a singly linked list, group all odd nodes together followed by the even nodes. P
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 138. Copy List with Random Pointer A linked list is given such that each node contains an additional random poin
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it witho
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list should be mad
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 52 两个链表的第一个公共结点 题目描述 输入两个链表,找出它们的第一个公共结点。 /* struct ListNode { int val; struct ListNode *next; ListNode(int x) :
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 19. Remove Nth Node From End of List Given a linked list, remove the n-th node from the end of list and return i
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly linked list, given
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 6 从尾到头打印链表 题目描述 输入一个链表,从尾到头打印链表每个节点的值 /** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 206. Reverse Linked List Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 59 队列(滑动窗口)的最大值 题目一:滑动窗口的最大值 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值。例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 31 栈的压入、弹出序列 题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 155. Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 232. Implement Queue using Stacks Implement the following operations of a queue using stacks. push(x) -- Push el
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 225. Implement Stack using Queues Implement the following operations of a stack using queues. push(x) -- Push el
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 263. Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are positive nu
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 204. Count Primes Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Outpu
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 400. Nth Digit Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note:
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 233. Number of Digit One Given an integer n, count the total number of digit 1 appearing in all non-negative int
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 136. Single Number Given a non-empty array of integers, every element appears twice except for one. Find that si
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 191. Number of 1 Bits Write a function that takes an unsigned integer and returns the number of '1' bits it has
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 位运算规律总结 1 与运算 //(对于某位为1的bit_mask,一个数如果该比特位为1,与bit_mask相与得1,否则得0) if(a & 1 == 0) //偶数 if(a & 1 == 1) //奇数 (n-1) &
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Set Matrix Zeroes Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Kth Smallest Element in a Sorted Matrix Given a n x n matrix where each of the rows and columns are sorted in as
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 74. Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This matrix ha
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 54. Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spi
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 20 表示数值的字符串(了解即可) 题目描述 请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。 但是"12e","
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 19 正则表达式匹配(hard,了解即可) 题目描述 请实现一个函数用来匹配包括'.'和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次)。 在本题中,匹配是指字符串的
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Count and Say The count-and-say sequence is the sequence of integers with the first five terms as following: 1.
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 3. Longest Substrleftng Without Repeating Characters Given a string, find the length of the longest substring wi
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 242. Valid Anagram (变位词) Given two strings s and t , write a function to determine if t is an anagram of s. Exam
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You may assume that
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Valid Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if th
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Valid Palindrome Given a string, determine if it is a palindrome, consider
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings. If
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 38 字符串的排列(全排列问题) 题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。 输入
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Implement strStr() Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) String to Integer (atoi) Implement atoi which converts a string to an integer. The function first discards as ma
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 67 把字符串转成整数 题目描述 将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数。 数值为0或者字符串不是一个合法的数值则返回0 输入描述: 输入一个字符串,包括数字字母符号,可以为空 输出描述: 如果是合法
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 58 翻转字符串 题目一:翻转单词顺序 牛客最近来了一个新员工Fish,每天早晨总是会拿着一本英文杂志,写些句子在本子上。同事Cat对Fish写的内容颇感兴趣,有一天他向Fish借来翻看,但却读不懂它的意思。例如,“stud
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 E
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Reverse String Write a function that takes a string as input and returns the string reversed. Example: Given s =
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 5 替换空格 题目描述 请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。 /* 链接:https://www.nowc
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 387. First Unique Character in a String Given a string, find the first non-repeating character in it and return
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise).
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Valid Sudoku Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to t
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Move Zeroes Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Plus One Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The dig
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Increasing Triplet Subsequence Given an unsorted array return whether an increasing subsequence of length 3 exis
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 51 数组中的逆序对 题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。输入一个数组,求出这个数组中的逆序对的总数P。并将P对1000000007取模的结果输出。 即输出P%10000
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 45 把数组排成最小的数 题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323。 /* 链接
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 61 扑克牌中的顺子 从扑克牌中随机抽 5 张牌,判断是不是顺子,即这 5 张牌是不是连续的。 2-10 为数字本身,A 为 1,J 为 11,Q 为 12,K 为 13,而大小王可以看成任意的 数字。(大小王最多4张) 思
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 21 调整数组顺序使奇数位于偶数前面 题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变。 /*
阅读全文
摘要:66 构建乘积数组 66 构建乘积数组 66 构建乘积数组 题目描述 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]。不能使用除法。 思路: B[i]的值可以看
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 228. Summary Ranges Given a sorted integer array without duplicates, return the summary of its ranges. Example 1
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 349. Intersection of Two Arrays Given two arrays, write a function to compute their intersection. Example: Given
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 189. Rotate Array(相当于循环右移k位) Given an array, rotate the array to the right by k steps, where k is non-negative.
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 53 数字在排序数组中出现的次数 题目描述 统计一个数字在排序数组中出现的次数。 //方法一:顺序扫描,统计出现的次数,O(n) /* 方法二:由于是有序数组,可以用二分查找 用stl中函数 lower_bound 和 up
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 39 数组中出现次数超过一半的数字 题目描述 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}。由于数字2在数组中出现了5次,超过数组长度的一半,
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 26. Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place such that each
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 287. Find the Duplicate Number Given an array nums containing n + 1 integers where each integer is between 1 and
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your function should r
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 3Sum Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all uni
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 57 有序数组中和为s的两个数 题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的。 输出描述: 对应每个测试案例,输出两个数,小的先输出
阅读全文
摘要:【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specific tar
阅读全文