提交 1bec6b9f 编写于 作者: ToTensor's avatar ToTensor

optimize exercises

上级 7b7ff8f5
......@@ -20,7 +20,7 @@ for i in range(n,n+1):
if i % 2 == 0:
for k in range(2, i):
if a(k) == 1 and a(i - k) == 1:
________________
________________;
```
## template
......
......@@ -8,7 +8,7 @@
n = int(input("输入数字:"))
factor = [n]
num = 1
__________________
__________________;
print(factor)
m = [str(i) for i in factor]
count4 = 0
......
......@@ -12,7 +12,7 @@ K=0
for i in range(1,N+1):
x,y=random(),random()
dist =sqrt(x**2+y**2)
_____________________
_____________________;
pi=4*(K/N)
print("圆周率值:{}".format(pi))
```
......
......@@ -41,7 +41,7 @@ x2 = x1.split(",")
a = []
b = []
for i in x2:
______________
______________;
if a == []:
print("NONE")
else:
......
......@@ -26,7 +26,7 @@ int main()
{
for (int j = 0; j < N - i; j++)
printf(" ");
______________________
______________________;
printf("\n");
}
return 0;
......
......@@ -29,7 +29,7 @@ int main()
return 0;
}
int *a = (int *)malloc(sizeof(int) * n);
__________________
__________________;
scanf("%d", &m);
if (m < 0 || m >= n)
{
......
......@@ -12,7 +12,7 @@ void funShift(int m, char *p, int n)
char c;
for (int j = 0; j < m; j++)
{
_____________________
_____________________;
}
}
int main()
......
......@@ -44,7 +44,7 @@ int main()
sum = 0;
while (a < n)
{
__________________
__________________;
if (j == i)
{
sum += i;
......
......@@ -22,7 +22,7 @@ int fun(string str)
int score = 0;
for (int i = 0; i < str.length(); i++)
{
_____________________
_____________________;
}
if (index == -1)
{
......
......@@ -40,7 +40,7 @@ double sin(double x)
{
int i = 0;
double result = 0, n = 0;
____________________
____________________;
return result;
}
double nResult(double x, double n)
......
......@@ -20,7 +20,7 @@ int main()
}
break;
}
__________________
__________________;
printf("sum=%d\n", sum);
return 0;
}
......
......@@ -37,7 +37,7 @@ private:
{
return;
}
_____________________
_____________________;
}
};
```
......
......@@ -23,7 +23,7 @@ private:
res.push_back(stack);
for (int i = start; i < nums.size(); i++)
{
______________
______________;
}
}
};
......
......@@ -41,7 +41,7 @@ static int uniquePaths(int m, int n)
{
for (col = 1; col < m; col++)
{
______________________________
______________________________;
}
}
return grids[m * n - 1];
......
......@@ -29,7 +29,7 @@ public:
}
for ( auto& it : str[k] ) {
ans.push_back( it );
_____________________
_____________________;
ans.pop_back();
}
}
......
......@@ -69,7 +69,7 @@ static struct TreeNode *dfs(int low, int high, int *count)
for (i = low; i <= high; i++)
{
int left_cnt, right_cnt;
________________________________
________________________________;
if (left_cnt == 0)
left_cnt = 1;
if (right_cnt == 0)
......
......@@ -128,7 +128,7 @@ public static int myAtoi(String str) {
if (base > Integer.MAX_VALUE / 10 || (base == Integer.MAX_VALUE / 10 && str.charAt(i) - '0' > 7)) {
return (sign == 1) ? Integer.MAX_VALUE : Integer.MIN_VALUE;
}
____________________
____________________;
}
return base * sign;
}
......
......@@ -44,7 +44,7 @@ public:
{
for (int j = 0; j < i; j++)
{
___________________
___________________;
}
}
return sum[n];
......
......@@ -56,7 +56,7 @@ int **insert(int **intervals, int intervalsSize, int *intervalsColSize, int *new
if (tmp[i * 2] > results[len][1])
{
len++;
________________________
________________________;
}
else if (tmp[i * 2 + 1] > results[len][1])
{
......
......@@ -26,7 +26,7 @@ public:
{
if (k > j + 1 && nums[k] == nums[k - 1])
continue;
_____________________________
_____________________________;
if (k >= l)
{
break;
......
......@@ -90,7 +90,7 @@ static void parse(char *input, char *output)
n += count % 10;
count /= 10;
}
____________________
____________________;
*q++ = p[0];
p++;
}
......
......@@ -36,7 +36,7 @@ public:
ListNode *prev = &dummy;
ListNode *p = head;
k = k % len;
_______________________
_______________________;
if (p != nullptr)
{
prev->next = tail->next;
......
......@@ -32,7 +32,7 @@ private:
for (int i = start; i <= n; i++)
{
stack.push_back(i);
_____________________
_____________________;
stack.pop_back();
}
}
......
......@@ -24,7 +24,7 @@ public:
lc--;
if (lc > rc)
{
_________________
_________________;
}
}
vector<string> generateParenthesis(int n)
......
......@@ -19,7 +19,7 @@ public:
for (int j = low; j < high; j++)
{
int tmp = matrix[i][j];
_________________________
_________________________;
}
}
}
......
......@@ -15,7 +15,7 @@ public:
for (int i = 0, j = height.size() - 1; i < j;)
{
temp = min(height[i], height[j]) * (j - i);
______________________
______________________;
}
return ret;
}
......
......@@ -38,7 +38,7 @@ static void dfs(char *s, int start, char *stack, int num, char **results, int *c
for (j = 0; j < num; j++)
{
char *q = stack + j * WIDTH;
______________________
______________________;
}
(*count)++;
}
......
......@@ -22,7 +22,7 @@ int *grayCode(int n, int *returnSize)
}
int i, count = 1 << n;
int *codes = malloc(count * sizeof(int));
_________________
_________________;
return codes;
}
int main(int argc, char **argv)
......
......@@ -24,7 +24,7 @@ public:
if (i >= 0)
{
int j = nums.size() - 1;
________________________
________________________;
swap(nums.begin() + i, nums.begin() + j);
}
reverse(nums.begin() + i + 1, nums.end());
......
......@@ -28,7 +28,7 @@ private:
if (last != nums[i])
{
stack.push_back(nums[i]);
____________________
____________________;
stack.pop_back();
}
last = nums[i];
......
......@@ -77,7 +77,7 @@ static char *simplifyPath(char *path)
{
for (i = 0; i < depth; i++)
{
____________________
____________________;
}
}
*q = '\0';
......
......@@ -34,7 +34,7 @@ struct ListNode *addTwoNumbers(struct ListNode *l1, struct ListNode *l2)
pp->next = p = q;
qp->next = NULL;
}
____________________
____________________;
if (carry)
{
struct ListNode *n = (struct ListNode *)malloc(sizeof(struct ListNode));
......
......@@ -31,7 +31,7 @@ struct ListNode *partition(struct ListNode *head, int x)
{
if (p->val < x)
{
__________________
__________________;
}
else
{
......
......@@ -100,7 +100,7 @@ char *intToRoman(int num)
int i = 0;
while (num)
{
______________
______________;
else
{
i++;
......
......@@ -32,7 +32,7 @@ private:
{
if (!used[i])
{
_____________________
_____________________;
stack.push_back(nums[i]);
used[i] = true;
dfs(nums, used, res);
......
......@@ -14,7 +14,7 @@ int lengthOfLongestSubstring(char *s)
memset(hset, 0, sizeof hset);
for (; s[j]; j++)
{
___________________
___________________;
}
return m;
}
......
......@@ -46,7 +46,7 @@ static int numDecodings(char *s)
int c = b;
for (int i = 2; i <= len; i++)
{
_________________
_________________;
a = b;
b = c;
}
......
......@@ -33,7 +33,7 @@ public:
unsigned int res = 0;
while (dvd >= dvs)
{
________________
________________;
}
if (signal == 1 && res >= INT_MAX)
{
......
......@@ -30,7 +30,7 @@ public:
{
ans.push_back(matrix[i][col - 1 - cir]);
}
__________________
__________________;
for (int i = row - 2 - cir; i > cir && (col - 1 - cir != cir); i--)
{
ans.push_back(matrix[i][cir]);
......
......@@ -31,7 +31,7 @@ private:
{
if (!used[i])
{
_______________
_______________;
}
}
}
......
......@@ -48,7 +48,7 @@ public:
}
if (nums[lo] <= nums[mid])
{
____________
____________;
}
else
{
......
......@@ -24,7 +24,7 @@ static int binary_search(int *nums, int len, int target)
high = mid;
}
}
______________________
______________________;
else
{
return high;
......
......@@ -19,7 +19,7 @@ public:
}
else
{
___________________
___________________;
}
}
private:
......
......@@ -31,7 +31,7 @@ public:
string key;
for (int i : counts)
{
________________
________________;
}
ht[key].push_back(str);
}
......
......@@ -30,7 +30,7 @@ public:
{
for (int n = 0; n < j; n++)
{
__________________
__________________;
}
}
}
......
......@@ -70,7 +70,7 @@ private:
while (lo + 1 < hi)
{
int mid = lo + (hi - lo) / 2;
______________
______________;
}
if (lo == -1 || nums[lo] != target)
{
......
......@@ -23,7 +23,7 @@ public:
while (hi < nums.size() - 1)
{
int right = 0;
_______________________
_______________________;
hi = right;
steps++;
}
......
......@@ -26,7 +26,7 @@ static struct ListNode *reverseBetween(struct ListNode *head, int m, int n)
for (i = m; i < n; i++)
{
struct ListNode *q = p->next;
__________________
__________________;
}
return dummy.next;
}
......
......@@ -37,7 +37,7 @@ int minPathSum(int **grid, int gridRowSize, int gridColSize)
{
for (j = 1; j < gridColSize; j++)
{
_____________________
_____________________;
}
}
return dp[gridRowSize - 1][gridColSize - 1];
......
......@@ -27,7 +27,7 @@ public:
pv.push_back(p);
p = p->next;
}
_________________
_________________;
p->next = p->next->next;
return empty_node.next;
}
......
......@@ -52,7 +52,7 @@ private:
for (int i = start; i < candidates.size(); i++)
{
stack.push_back(candidates[i]);
_____________________________
_____________________________;
stack.pop_back();
}
}
......
......@@ -39,7 +39,7 @@ public:
break;
}
t--;
________________
________________;
}
s[ti + maxlen] = 0;
return s.c_str() + ti;
......
......@@ -55,7 +55,7 @@ static bool search(int *nums, int numsSize, int target)
}
else if (nums[lo] <= nums[mid])
{
___________________
___________________;
}
else
{
......
......@@ -47,7 +47,7 @@ static int removeDuplicates(int *nums, int numsSize)
{
if (nums[len] == nums[i])
{
_____________________
_____________________;
}
else
{
......
......@@ -32,7 +32,7 @@ static bool isInterleave(char *s1, char *s2, char *s3)
}
for (i = 1; i < len2 + 1; i++)
{
____________________
____________________;
}
for (i = 1; i < len1 + 1; i++)
{
......
......@@ -34,7 +34,7 @@ int **merge(int **intervals, int intervalsSize, int *intervalsColSize, int *retu
if (tmp[i * 2] > intervals[len][1])
{
len++;
___________________________
___________________________;
}
else if (tmp[i * 2 + 1] > intervals[len][1])
{
......
......@@ -31,7 +31,7 @@ public:
{
r.emplace_back(vector<int>({nums[cur], nums[left], nums[right]}));
int t = left + 1;
__________________________
__________________________;
}
else if (n > 0)
{
......
......@@ -18,7 +18,7 @@ public:
int j, carry = 0;
for (j = num1.length() - 1; j >= 0; j--)
{
_____________________
_____________________;
}
res[i + j + 1] = carry + '0';
}
......
......@@ -31,7 +31,7 @@ public:
{
break;
}
____________________________
____________________________;
else
{
int t = left + 1;
......
......@@ -17,7 +17,7 @@ static bool canJump(int *nums, int numsSize)
int i, pos = 0;
for (i = 0; i < numsSize - 1; i++)
{
___________________
___________________;
pos = max(i + nums[i], pos);
}
return pos >= numsSize - 1;
......
......@@ -36,7 +36,7 @@ static bool dfs(char *word, char **board, bool *used,
}
if (!result && col < col_size - 1 && !used[row * col_size + col + 1])
{
__________________________
__________________________;
}
used[row * col_size + col] = false;
return result;
......
......@@ -69,7 +69,7 @@ public:
{
root = stk.top();
stk.pop();
_______________________
_______________________;
}
}
return true;
......
......@@ -21,7 +21,7 @@ struct ListNode *deleteDuplicates(struct ListNode *head)
p = q = head;
while (p != NULL)
{
_____________________
_____________________;
}
return dummy.next;
}
......
......@@ -85,7 +85,7 @@ public:
}
if (left)
{
_____________________
_____________________;
}
}
for (i = 0; i < full_cycles; ++i)
......
......@@ -48,7 +48,7 @@ private:
if (last != candidates[i])
{
stack.push_back(candidates[i]);
_________________________________
_________________________________;
stack.pop_back();
}
last = candidates[i];
......
......@@ -17,7 +17,7 @@ public:
ans[0][0] = 1;
while (cnt < n * n)
{
___________________
___________________;
time++;
}
return ans;
......
......@@ -25,7 +25,7 @@ public:
while (p != nullptr && p->next != nullptr)
{
struct ListNode *q = p->next;
_____________________
_____________________;
}
return dummy.next;
}
......
......@@ -30,7 +30,7 @@ public:
j = nums.size() - 1;
while (i < j)
{
_____________________
_____________________;
swap(nums[i], nums[j]);
}
}
......
......@@ -76,7 +76,7 @@ static int uniquePathsWithObstacles(int **obstacleGrid, int obstacleGridRowSize,
int *line = obstacleGrid[row];
for (col = 1; col < obstacleGridColSize; col++)
{
________________________
________________________;
}
}
return obstacleGrid[obstacleGridRowSize - 1][obstacleGridColSize - 1];
......
......@@ -88,7 +88,7 @@ public:
vector<bool> mark(10);
for (int i = sr; i < sr + 3; i++)
{
________________________
________________________;
}
}
return true;
......
......@@ -23,7 +23,7 @@ def deal(data,flag):
elif a==[]:
a.append([i])
else:
_______________________
_______________________;
a.append([i])
target=sum(max(a,key=sum))
return list(filter(lambda x:sum(x)==target,a))
......
......@@ -30,7 +30,7 @@ def lcm(x, y):
else:
greater = y
while(True):
____________________
____________________;
greater += 1
return lcm
num1 = int(input("输入第一个数字: "))
......
......@@ -26,7 +26,7 @@ int main()
temp = 0;
cin >> n1 >> n2 >> n3;
temp += n1 * x + n2 * y + n3 * z;
__________________
__________________;
}
cout << t << " " << min;
return 0;
......
......@@ -28,7 +28,7 @@ void solve()
printf("\n");
for (j = 0; j < n; j++)
{
___________________
___________________;
for (k = 1; k <= Y; k++)
printf("%-3d", Min[k]);
printf("\n");
......
......@@ -46,7 +46,7 @@ int main()
auto status = 0;
for (; j < n; ++j)
{
______________
______________;
}
if (status == 0)
{
......
......@@ -17,7 +17,7 @@ int main() {
return 0;
}
int total(int x) {
_________________
_________________;
}
```
......
......@@ -32,7 +32,7 @@ int main()
}
for (i = 1; i < strlen(a); i++)
{
________________
________________;
}
if (zyy && !fyy)
{
......
......@@ -40,7 +40,7 @@ int main()
for (long long i = 2; i <= c; i = sum / k + 1)
{
int t = num;
________________
________________;
}
cout << "Case #" << count++ <<": " << num << endl;
}
......
......@@ -19,7 +19,7 @@ int sushu(int x)
int i, j = 1;
for (i = 2; i <= sqrt(x); i++)
{
_______________
_______________;
}
return j;
}
......
......@@ -26,7 +26,7 @@ int binary(int *a, int key, int n)
mid = (left + right) / 2;
while (left < right && a[mid] != key)
{
_________________
_________________;
}
if (a[mid] == key)
return mid;
......
......@@ -20,7 +20,7 @@ void paixu(float *p, int n)
if (fabs(p[j]) < fabs(p[j + 1]))
{
float tmp;
_______________
_______________;
}
}
}
......
......@@ -49,7 +49,7 @@ void shuchu(char *a, int m, int n)
else
{
cout << a[(m + n) / 2];
_______________________
_______________________;
}
}
int main()
......
......@@ -31,7 +31,7 @@ void JosePhus(int n, int m, int start)
{
start--;
int index = (start + m - 1) % sum;
______________
______________;
sum--;
count++;
}
......
......@@ -19,7 +19,7 @@
#include <complex>
using namespace std;
static const double e = 1e-12;
_______________________________
_______________________________;
int main()
{
complex<double> a, b, c;
......
......@@ -112,7 +112,7 @@ private:
rows[row][i] = true;
cols[col][i] = true;
boxes[idx][i] = true;
_______________________________
_______________________________;
if (!ok)
{
rows[row][i] = false;
......
......@@ -17,7 +17,7 @@ public:
int right = height.size() - 1, right_max = 0;
while (left < right)
{
_____________________
_____________________;
}
return res;
}
......
......@@ -33,7 +33,7 @@ static int largestRectangleArea(int *heights, int heightsSize)
indexes[pos++] = i;
}
int max_area = 0;
_______________________
_______________________;
return max_area;
}
int main(void)
......
......@@ -19,7 +19,7 @@ public:
int i = 0;
while (i < nums.size())
{
____________________________
____________________________;
}
for (i = 0; i < nums.size(); i++)
{
......
......@@ -63,7 +63,7 @@ private:
if (row == 0 || !conflict(stack, row, i))
{
stack[row] = i;
_______________________
_______________________;
}
}
return count;
......
......@@ -116,7 +116,7 @@ int main()
if (temp.time - 86400 >= old.time)
{
int tc = old.country;
_________________________
_________________________;
q.pop();
}
else
......
......@@ -41,7 +41,7 @@ int main()
t = -1;
for (i = 0; i < n - 1; i++)
{
____________________
____________________;
}
b[j] = n - 1 - t;
c[j] = n - 1;
......
......@@ -65,7 +65,7 @@ void dfs(int x)
}
for (int i = 1; i < 13; ++i)
{
________________
________________;
}
}
int main()
......
......@@ -20,7 +20,7 @@ int main()
a = j;
while (j != 0)
{
______________
______________;
}
j = a;
if (sum == a)
......
......@@ -19,7 +19,7 @@ void InsertSort(int a[], int n)
{
int j = i - 1;
int x = a[i];
________________
________________;
}
}
}
......
......@@ -24,7 +24,7 @@ string StrCon(const string& a, const string& b)
c += a[i];
c += b[i];
}
__________________
__________________;
return c;
}
int main()
......
......@@ -18,7 +18,7 @@ int main()
scanf("%d", &a[i]);
if (i % 2 == 1)
{
__________________
__________________;
}
}
for (i = n - 1; i >= 0; i--)
......
......@@ -41,7 +41,7 @@ def maze(m, n, route, pos, export):
maze(m, n, route[:], (pos[0]+1,pos[1]), export)
if pos[1] > 0 and m[pos[0]][pos[1]-1] == 0 and (pos[0],pos[1]-1) not in route:
maze(m, n, route[:], (pos[0],pos[1]-1), export)
________________________________
________________________________;
m = [
[1,1,1,0,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,1,1],
......
......@@ -16,7 +16,7 @@ class Solution(object):
if curr == '(':
stack.append(i)
else:
__________________
__________________;
tep, res = 0, 0
for t in data:
if t == 1:
......
......@@ -23,7 +23,7 @@ class Solution(object):
for i in range(pos):
for j in range(ls):
if board[i][j] == 'Q':
______________________
______________________;
for j in range(ls):
if check[j]:
board[pos][j] = 'Q'
......
......@@ -75,7 +75,7 @@ class Solution(object):
return memo[s1, s2]
n = len(s1)
for i in range(1, n):
___________________________
___________________________;
memo[s1, s2] = False
return False
# %%
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册