![](https://img-blog.csdnimg.cn/20190927151117521.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Leetcode解题
LeetCode刷题合集,以及部分面试题也会发布在这里
九里写代码
这个作者很懒,什么都没留下…
展开
-
面试题:Java回形数组
最近遇到一个面试题。给定一个数字n,输出一个n阶矩阵。矩阵中的元素为1到n²。按回形排列eg1 :输入:n=2输出:1 24 3eg2:输入:n=3输出:1 2 38 9 47 6 5思路:这个题属于现实中遇到很简单,但是程序实现还是有些难度的问题。面试的时候面试官让我手写出这个问题的解法,无奈最后实在没写出来。纸上写代码太难了。这个问题其实需要分成三个层次去看。第一层看出来,此问题需要一个二维数组解决第二层看出来,此问题一个有四种操作数组的情况原创 2020-10-14 09:03:40 · 434 阅读 · 0 评论 -
[LeetCode]3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the le原创 2017-11-24 10:01:50 · 201 阅读 · 0 评论 -
[LeetCode] 654. Maximum Binary Tree
Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array.原创 2017-11-13 14:54:34 · 226 阅读 · 0 评论 -
LeetCode(476): Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the range of a 32原创 2017-11-13 14:43:34 · 223 阅读 · 0 评论 -
Leetcode(93): Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order does not原创 2017-11-13 14:43:10 · 123 阅读 · 0 评论 -
LeetCode(144):Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3].Note: Recursive solution is原创 2017-11-13 14:43:05 · 134 阅读 · 0 评论 -
LeetCode (258):Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one dig原创 2017-11-13 14:42:32 · 161 阅读 · 0 评论 -
LeetCode (237):Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3原创 2017-11-13 14:42:36 · 123 阅读 · 0 评论 -
LeetCode (65):Same tree
Total Accepted: 83663 Total Submissions: 200541 Difficulty: Easy Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are原创 2017-11-13 14:42:41 · 128 阅读 · 0 评论 -
LeetCode (226):Invert Binary Tree 递归实现
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by Max Ho原创 2017-11-13 14:42:46 · 118 阅读 · 0 评论 -
LeetCode (236):Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between原创 2017-11-13 14:42:51 · 203 阅读 · 0 评论 -
LeetCode (262):Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2017-11-13 14:42:55 · 139 阅读 · 0 评论 -
LeetCode (238):Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).原创 2017-11-13 14:43:00 · 127 阅读 · 0 评论