随笔分类 -  算法

本分类用于存放一些算法题,主要来源于Leetcode。
摘要:题目 Given an integer n, return true if it is a power of two. Otherwise, return false. An integer n is a power of two, if there exists an integer x such 阅读全文
posted @ 2022-03-10 15:45 frankming 阅读(31) 评论(0) 推荐(0)
摘要:题目 Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More fo 阅读全文
posted @ 2022-03-10 00:20 frankming 阅读(39) 评论(0) 推荐(0)
摘要:题目 You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping 阅读全文
posted @ 2022-03-09 19:45 frankming 阅读(30) 评论(0) 推荐(0)
摘要:题目 You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you cli 阅读全文
posted @ 2022-03-09 19:32 frankming 阅读(31) 评论(0) 推荐(0)
摘要:题目 Given a string s, you can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible 阅读全文
posted @ 2022-03-09 19:26 frankming 阅读(34) 评论(0) 推荐(0)
摘要:题目 Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1: Input: nums = [1 阅读全文
posted @ 2022-03-09 19:09 frankming 阅读(26) 评论(0) 推荐(0)
摘要:题目 Given two integers n and k, return all possible combinations of k numbers out of the range [1, n]. You may return the answer in any order. Example 阅读全文
posted @ 2022-03-08 15:14 frankming 阅读(28) 评论(0) 推荐(0)
摘要:题目 Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Ex 阅读全文
posted @ 2022-03-08 14:26 frankming 阅读(38) 评论(0) 推荐(0)
摘要:题目 You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following de 阅读全文
posted @ 2022-03-08 14:05 frankming 阅读(37) 评论(0) 推荐(0)
摘要:题目 You are given the heads of two sorted linked lists list1 and list2. Merge the two lists in a one sorted list. The list should be made by splicing t 阅读全文
posted @ 2022-03-03 23:58 frankming 阅读(54) 评论(0) 推荐(0)
摘要:题目 You are given an m x n grid where each cell can have one of three values: 0 representing an empty cell, 1 representing a fresh orange, or 2 represe 阅读全文
posted @ 2022-03-03 16:15 frankming 阅读(43) 评论(0) 推荐(0)
摘要:题目 Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Example 1: Inpu 阅读全文
posted @ 2022-03-03 00:16 frankming 阅读(28) 评论(0) 推荐(0)
摘要:题目 You are given two binary trees root1 and root2. Imagine that when you put one of them to cover the other, some nodes of the two trees are overlappe 阅读全文
posted @ 2022-03-01 23:56 frankming 阅读(36) 评论(0) 推荐(0)
摘要:题目 You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You 阅读全文
posted @ 2022-03-01 23:18 frankming 阅读(38) 评论(0) 推荐(0)
摘要:题目 An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image. You are also given three integers 阅读全文
posted @ 2022-02-27 23:55 frankming 阅读(36) 评论(0) 推荐(0)
摘要:题目 Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return true if one of s1's permuta 阅读全文
posted @ 2022-02-27 01:52 frankming 阅读(31) 评论(0) 推荐(0)
摘要:题目 Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: Th 阅读全文
posted @ 2022-02-26 22:08 frankming 阅读(27) 评论(0) 推荐(0)
摘要:题目 Given the head of a linked list, remove the nth node from the end of the list and return its head. Example 1: Input: head = [1,2,3,4,5], n = 2 Outp 阅读全文
posted @ 2022-02-26 00:01 frankming 阅读(26) 评论(0) 推荐(0)
摘要:题目 Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node. Ex 阅读全文
posted @ 2022-02-25 23:39 frankming 阅读(33) 评论(0) 推荐(0)
摘要:题目 Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Example 阅读全文
posted @ 2022-02-25 22:16 frankming 阅读(17) 评论(0) 推荐(0)