Home > Back-end >  Leecode record
Leecode record

Time:11-01

1 + 2 + 1,... + n, requirement, method, and cannot be used for, while, the if, else, switch, case and other keyword and conditional statements (A? B: C),
-- -- -- -- -- -- -- -- -- -- -- -- the use of recursive thinking,

CodePudding user response:

2, write a function that no temporary variables, direct exchange Numbers=(a, b) values of a and b,
Use opportunely xor,
A=a ^ b
B=a ^ b (i.e., a ^ ^ b b=a)
A=a ^ b (i.e., a b ^ ^ a=b)

CodePudding user response:

How could a recursive without condition statement? That how to determine when to end the recursion?
Recursive functions is usually so write:
 
Int the sum (int n)
{
Static int x=0;
If (n==1) return x + 1;
X +=n;
Return the sum (n - 1);
}

CodePudding user response:

references the frog studio reply: 3/f
how can recursively without conditional statements? That how to determine when to end the recursion?
Recursive functions is usually so write:
 
Int the sum (int n)
{
Static int x=0;
If (n==1) return x + 1;
X +=n;
Return the sum (n - 1);
}

Using the short circuit characteristic, reference a way for
Int sumNums (int n) {
Int sum=n;
N & amp; & (sum +=sumNums (n - 1));
return sum;
}
N & amp; & (sum +=sumNums (n - 1)); When the judge n & gt; 0 and (sum & gt; 0) then perform sum +=sumNums (n - 1) continue to recursion, equivalent to the if statement if (n & gt; 0) sum +=sumNums (n - 1), if n & lt; 0, then no longer continue to judge sume values, but return, equivalent to the else return sum

Author: shi qi - chan - yi - shao - nian
Link: https://leetcode-cn.com/problems/qiu-12n-lcof/solution/cdi-gui-de-jian-dan-xie-fa-bu-yong-cheng-chu-fa-if/
Source: the power button (LeetCode)
Copyright owned by the author, commercial reproduced please contact the author for authorization, non-commercial reprint please indicate the source,
Author: shi qi - chan - yi - shao - nian
Link: https://leetcode-cn.com/problems/qiu-12n-lcof/solution/cdi-gui-de-jian-dan-xie-fa-bu-yong-cheng-chu-fa-if/
Source: the power button (LeetCode)
Copyright owned by the author, commercial reproduced please contact the author for authorization, non-commercial reprint please indicate the source,

CodePudding user response:

In two dimensional array in the grid, the grid [I] [j] represents the height of buildings in somewhere, we are allowed to add any number (the number of different buildings may be different) the height of the building, level 0 is also considered building,

Finally, the new array of all the four direction (namely the top, bottom, left and right) to watch the "skyline" must be the same as the original array's skyline, the city's skyline when viewed from a distance, formed by all buildings rectangular outer contour, please look at the following example,

How much is the building height can increase the maximum sum?

Example:
Input: the grid=[,0,8,4 [3], [2,4,5,7],,2,6,3 [9], [0,3,1,0]]
Output: 35
Explanation:
The grid is:
[[3, 0, 8, 4],
[2, 4, 5, 7),
[9, 2, 6, 3],
[0, 3, 1, 0]]

From an array of vertical direction (i.e., the top and bottom) see "skyline" is: [9, 4, 8, 7]
From the level of horizontal direction (i.e., left, right) to see "skyline" is: [8, 7, 9, 3]

Without affecting the skyline of buildings under the condition of higher after the new array is as follows:

GridNew=[7] [8, 4, 8,,
(7, 4, 7, 7),
[9, 4, 8, 7],
[3, 3, 3, 3]]
Description:

1 The height of the grid [I] [j] scope is: [0, 100],
Occupy a building a grid [I] [j] : in other words, they are 1 x 1 x grid [I] [j] cuboid,

Source: the power button (LeetCode)
Link: https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline
Copyright belongs to the collar of the network, commercial reproduced please contact the official authorization, non-commercial reprint please indicate the source,

To calculate the maximum of each row and each column of the maximum, traversed, increased to the maximum height of each building skyline for the element row and column skyline of smaller value highly,
Time complexity O (n2), space complexity (O (N))

CodePudding user response:

Without repeating the permutation and combination of the string, write a method of calculating all the permutation and combination, a string string each character are not the same,
Example 1:

Input: S="qwe"
Output: [" qwe qew ", ""," wqe ", "weq," "ewq", "eqw"]
Example 2:

Input: S="ab"
Output: [" ab ", the "ba"]
Tip:

Characters are letters,
The length of the string between [1, 9],

Source: the power button (LeetCode)
Link: https://leetcode-cn.com/problems/permutation-i-lcci
Copyright belongs to the collar of the network, commercial reproduced please contact the official authorization, non-commercial reprint please indicate the source,


Using backtracking

CodePudding user response:

The original poster is to take an examination of people? Topics are just understand homework for the students, but the original is to play some exotic curiosity-a solution looking,
The original poster for short-circuit characteristics, although available in c + +, but other no short circuit design language doesn't work,

CodePudding user response:

This is the basic language features, language support; seven 60 s

  • Related