Suba
Suba
Suba
class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
int ac = 0;
int bc = 0;
ListNode a = headA;
ListNode b = headB;
while(a != null){
ac++;
a = a.next;
}
while(b != null){
bc++;
b = b.next;
}
while(ac > bc){
ac--;
headA = headA.next;
}
while(bc > ac){
bc--;
headB = headB.next;
}
while(headA != headB){
headA = headA.next;
headB = headB.next;
}
return headA;
}
}
2. class Solution {
public:
string convertToTitle(int columnNumber) {
string res = "";
return res;
}
};
3. class Solution:
def titleToNumber(self, columnTitle: str) -> int:
ans, pos = 0, 0
for letter in reversed(columnTitle):
digit = ord(letter)-64
ans += digit * 26**pos
pos += 1
return ans
4. class Solution {
public:
int numSquares(int n) {
vector<int> dp(n + 1, INT_MAX);
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j * j <= i; ++j){
dp[i] = min(dp[i], dp[i - j * j] + 1);
}
}
return dp[n];
}
};
5. class Solution:
def __init__(self):
self.x = None
6. class Solution {
7. class Solution:
cnt = 1
for num in nums[1:]:
if num == nums[0]: cnt += 1
else:
if num % nums[0] != 0: return 1
return (cnt+1)//2
8. class Solution {
public:
vector<string> ans;
string space(int c) {
return string(c, ' ');
}
if (numGaps > 0) {
numSpaces = totalSpaces / numGaps;
remainingSpaces = totalSpaces % numGaps;
}
ans.push_back(line);
}
return ans;
}
9. #include <vector>
#include <climits>
class Solution {
public:
int calculateMinimumHP(vector<vector<int>>& d) {
int n = d.size();
int m = d[0].size();
// base condition 2
if (row >= n || col >= m) {
return INT_MAX;
}
if (dp[row][col] != 0) {
return dp[row][col];
}
return dp[row][col];
}
};
# If no crossing has been found, the path does not cross itself
return False