随笔分类 -  算法

本分类用于存放一些算法题,主要来源于Leetcode。
摘要:题目 Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot 阅读全文
posted @ 2022-03-24 23:07 frankming 阅读(21) 评论(0) 推荐(0)
摘要:题目 Given a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If th 阅读全文
posted @ 2022-03-21 23:57 frankming 阅读(32) 评论(0) 推荐(0)
摘要:题目 There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly w 阅读全文
posted @ 2022-03-20 23:59 frankming 阅读(105) 评论(0) 推荐(0)
摘要:题目 Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by 阅读全文
posted @ 2022-03-20 23:17 frankming 阅读(33) 评论(0) 推荐(0)
摘要:题目 Given an array of positive integers nums and a positive integer target, return the minimal length of a contiguous subarray [numsl, numsl+1, ..., nu 阅读全文
posted @ 2022-03-20 22:59 frankming 阅读(35) 评论(0) 推荐(0)
摘要:题目 Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray i 阅读全文
posted @ 2022-03-18 11:17 frankming 阅读(36) 评论(0) 推荐(0)
摘要:题目 Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order. An Anagram is a w 阅读全文
posted @ 2022-03-17 17:10 frankming 阅读(38) 评论(0) 推荐(0)
摘要:题目 You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, 阅读全文
posted @ 2022-03-17 16:30 frankming 阅读(26) 评论(0) 推荐(0)
摘要:题目 You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each 阅读全文
posted @ 2022-03-17 00:26 frankming 阅读(32) 评论(0) 推荐(0)
摘要:题目 Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character. Note that af 阅读全文
posted @ 2022-03-15 23:59 frankming 阅读(33) 评论(0) 推荐(0)
摘要:题目 Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums 阅读全文
posted @ 2022-03-15 15:15 frankming 阅读(41) 评论(0) 推荐(0)
摘要:题目 Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return 阅读全文
posted @ 2022-03-15 14:40 frankming 阅读(31) 评论(0) 推荐(0)
摘要:题目 A peak element is an element that is strictly greater than its neighbors. Given an integer array nums, find a peak element, and return its index. I 阅读全文
posted @ 2022-03-13 23:47 frankming 阅读(25) 评论(0) 推荐(0)
摘要:题目 Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become 阅读全文
posted @ 2022-03-13 23:25 frankming 阅读(26) 评论(0) 推荐(0)
摘要:题目 Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties: Integers 阅读全文
posted @ 2022-03-11 15:01 frankming 阅读(27) 评论(0) 推荐(0)
摘要:题目 There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated a 阅读全文
posted @ 2022-03-11 14:31 frankming 阅读(25) 评论(0) 推荐(0)
摘要:题目 Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not fou 阅读全文
posted @ 2022-03-11 14:16 frankming 阅读(34) 评论(0) 推荐(0)
摘要:题目 Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a li 阅读全文
posted @ 2022-03-11 00:02 frankming 阅读(22) 评论(0) 推荐(0)
摘要:题目 Reverse bits of a given 32 bits unsigned integer. Note: Note that in some languages, such as Java, there is no unsigned integer type. In this case, 阅读全文
posted @ 2022-03-10 23:48 frankming 阅读(28) 评论(0) 推荐(0)
摘要:题目 Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). Note: Note that in so 阅读全文
posted @ 2022-03-10 16:23 frankming 阅读(25) 评论(0) 推荐(0)